Friday, February 8, 2013

Pin It

Widgets

[PHP] PHP Cheat Sheet


PHP: Hypertext Preprocessor
The source is from
"PHP and MySQL For Dummies, 4th Edition"
Janet Valade
ISBN: 978-0-470-52758-0


Statements to Create Programs

A  list of the PHP statements (with syntax) that you use when writing PHP programs:
array ( "key" => "value", … );
die("message");
do { block } while (condition);
echo item;
extract($array);
for (startingval; endingval;incremnt) { block }
foreach( $array as $key => $value) { block }

function funcname(value,value,…) { block }
header("Location: URL");
if (condition) { block }
   elseif (condition) { block }
   else { block }
number_format(number,decimals);
session_start();
session_destroy();
switch var { case value statements break; … }
unset();
while (condition) { block }

Communicate with a Database through PHP MySQL Functions

PHP communicates with MySQL databases by using a set of functions developed specifically for this purpose. This list shows the syntax of these frequently used functions.
mysqli_connect("host","accnt","passwd")
mysqli_select_db($cxn, "dbname",)
mysqli_query($cxn,"query")
mysqli_fetch_assoc($result)
mysqli_num_rows($result)
mysqli_insert_id($cxn)

Make MySQL Database Changes with the ALTER Query

The ALTER query is used to change the structure of a MySQL database. This list shows the syntax for the changes you are most likely to want to make:
ADD colname definition
ALTER colname SET DEFAULT value
ALTER colname DROP DEFAULT
CHANGE colname newcolname definition
DROP colname
MODIFY colname definition
RENAME newtablename

Access and Adapt a Database with MySQL Queries

PHP communicates with MySQL databases by sending SQL queries. Here’s a list of SQL queries, with their syntax, that you can use to access, view, and alter the database:
ALTER TABLE table change
CREATE DATABASE database
CREATE TABLE (col def,…,PRIMARY KEY(col))
DELETE FROM tablename WHERE clause
DROP database|table
INSERT INTO table (col,col,…) VALUES (col,col,…)
LOAD DATA INFILE ″filename″ INTO TABLE table
SELECT col,col,… FROM table WHERE clause
SELECT statement UNION SELECT statement
SHOW DATABASES|TABLES
SHOW COLUMNS FROM table
UPDATE table SET col=value,… WHERE clause

Knowing the MySQL WHERE Clause Format

The WHERE clause is used to modify a DELETESELECT, or UPDATE SQL query. This list shows the format you can use when writing a WHERE clause:
WHERE exp AND|OR exp AND|OR exp
where exp can be one of the following:
column = value
column > value
column >= value
column < value
column <= value
column BETWEEN value1 AND value2
column IN (value1,value2,…)
column NOT IN (value1,value2,…)
column LIKE value
column NOT LIKE value

Special Characters to Use in PHP Expression Test Patterns

Regular PHP expressions use patterns to test whether the input users submit when using online forms are in the correct format. This table shows characters you can use in patterns.
CharacterMeaningExampleMatchNot a Match
^Beginning of line^ccatmy cat
$End of linec$ticstick
.Any single character..me, goa
?Preceding item is optionalmea?nmean, menmoan
( )Groups literal charactersm(ea)nmeanmen,mn
[ ]Any character in setabc[1-3]abc1,abc2abc4
[! ]Any character not in setm[!ea]nmin, monmen, man
+One or moredoor[1-3]+door111, door131door, door55
*Zero or moredoor[1-3]*door, door311door4, door445
{ , }Range of repetitionsa{2,5}aa,aaaaaa, xx3
\Escapes characterm\*nm*nmen, mean
( | | )Alternate strings(Tom|Tommy)Tom, TommyThomas, To

No comments:

Blogger Tricks And TipsComment here