P. 1
MYSQL & PHP Referance

MYSQL & PHP Referance

Ratings: (0)|Views: 635|Likes:
Published by jwzumwalt
A simple guide and reference for using MySql with PHP. Includes many simple examples. Most topics include a short 5 to 10 line program that demonstrates a concept.
A simple guide and reference for using MySql with PHP. Includes many simple examples. Most topics include a short 5 to 10 line program that demonstrates a concept.

More info:

Published by: jwzumwalt on Feb 07, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/13/2014

pdf

text

original

 
MySql Reference by Jan Zumwalt NeatInfo.com February, 06, 2012Pg - 1 of 43
MySql Glossary
 
Comments 
: #to end of line, or
--
to end of line, or /*across multiple lines.*/  
Field 
 
and
Column 
are usually synonymous.
Row 
 
and
Record 
 
are usually synonymous.
Table 
an organized collection of
Records 
.
Primary Key 
always unique (NOT NULL).
Normalized 
data in a table table, meets certain storage criteria such as a key, and ‘atom’ fieldcontents.
 
Indexes 
special columns the developer flags so the data engine may sort and may keepsecondary key lists to optimize performance.
Join 
combines the
common 
elements of two tables into a single table.If t1=a,b,c and t2=b,c,d then JOIN=b,c
Left Join 
The
left 
table in the Join statement is preserved even if there isn't a match with the righttable.If
 
t1=a,b,c and t2=b,c,d, then LEFT JOIN=a,b,c
 
MySql Reference by Jan Zumwalt NeatInfo.com February, 06, 2012Pg - 2 of 43
Table of Contents 
PHP COMMUNICATIONS WITH MYSQL......................................................................................................
 
SELECT & WHERE SYNTAX........................................................................................................................
 
MYSQL SIMPLE EXAMPLES .......................................................................................................................
 
STEP 1: CONNECT....................................................................................................................................................
 
STEP 2: QUERY.........................................................................................................................................................
 
STEP 3: FETCH RESULTS........................................................................................................................................
 
STEP 4: EXTRACT INFORMATION FROM FETCH..................................................................................................
 
SPECIFIC ROW DATA...............................................................................................................................................
 
ROW COUNT..............................................................................................................................................................
 
CLOSE CONNECTION...............................................................................................................................................
 
SIMPLE DATABASE EXAMPLE...................................................................................................................
 
MYSQL DEBUG EXAMPLES......................................................................................................................12 
 
EXAMPLE1: Hide mysql array values in html comment section…....................................................................12 
 
DATA TYPES..............................................................................................................................................13 
 
NUMERIC......................................................................................................................................................................13 
 
GEO SPATIAL...............................................................................................................................................................13 
 
FUNCTIONS ...............................................................................................................................................14 
 
TEXT..............................................................................................................................................................................14 
 
SYSTEM INFO............................................................................................................................................14 
 
PRIVILEGES...............................................................................................................................................16 
 
User Privileges.............................................................................................................................................................16 
 
Admin Privileges..........................................................................................................................................................16 
 
GRANT..........................................................................................................................................................................16 
 
PASSWORD..................................................................................................................................................................16 
 
COMMANDS...............................................................................................................................................17 
 
AS..................................................................................................................................................................................17 
 
CREATE........................................................................................................................................................................17 
 
COUNT..........................................................................................................................................................................17 
 
DELETE.........................................................................................................................................................................17 
 
DISTINCT......................................................................................................................................................................17 
 
INSERT..........................................................................................................................................................................17 
 
LIKE...............................................................................................................................................................................17 
 
ORDER BY....................................................................................................................................................................17 
 
PASSWORD..................................................................................................................................................................17 
 
SELECT.........................................................................................................................................................................17 
 
UPDATE........................................................................................................................................................................17 
 
WHERE .........................................................................................................................................................................17 
 
ALTER...........................................................................................................................................................................17 
 
ADD COLUMN..............................................................................................................................................................17 
 
CHANGE COLUMN.......................................................................................................................................................17 
 
DROPCOLUMN.............................................................................................................................................................17 
 
ADD INDEX...................................................................................................................................................................17 
 
DROP INDEX.................................................................................................................................................................17 
 
RENAME AS.................................................................................................................................................................17 
 
ENGINES....................................................................................................................................................17 
 
MyISAM.........................................................................................................................................................................17 
 
Memory (heap).............................................................................................................................................................17 
 
Merge............................................................................................................................................................................17 
 
InnoDB..........................................................................................................................................................................17 
 
Archive..........................................................................................................................................................................17 
 
Federated......................................................................................................................................................................17 
 
NDBCLUSTER (NDB)...................................................................................................................................................17 
 
CSV ...............................................................................................................................................................................17 
 
Blackhole......................................................................................................................................................................17 
 
Example........................................................................................................................................................................17 
 
 
MySql Reference by Jan Zumwalt NeatInfo.com February, 06, 2012Pg - 3 of 43
USER OPERATIONS..................................................................................................................................19 
 
DATABASE OPERATIONS ........................................................................................................................21
 
TABLE OPERATIONS................................................................................................................................22 
 
COLUMN OPERATIONS ............................................................................................................................23 
 
ROW OPERATIONS (SELECT)..................................................................................................................24 
 
Where conditions.........................................................................................................................................................24 
 
COUNT, SUM, MAX....................................................................................................................................26 
 
PHP & REGEX SEARCHS..........................................................................................................................27 
 
JOIN UNION GROUP............................................................................................................................28 
 
Test db setup:..............................................................................................................................................................28 
 
JOIN(default), INNER JOIN, and WHERE...................................................................................................................29 
 
LEFT JOIN.....................................................................................................................................................................30 
 
RIGHT JOIN..................................................................................................................................................................31
 
FULL JOIN, FULL OUTER JOIN, CROSS JOIN..........................................................................................................32 
 
UNION...........................................................................................................................................................................33 
 
GROUP..........................................................................................................................................................................34 
 
DATE & TIME FUNCTIONS........................................................................................................................35 
 
Date Datatypes 
...........................................................................................................................................................36 
 
DATE_FORMAT() 
........................................................................................................................................................36 
 
Extraction Functions...................................................................................................................................................38 
 
Getting the Current Date and Time 
.........................................................................................................................38 
 
Changing Date Values 
...............................................................................................................................................39 
 
USING PHP STATEMENTS........................................................................................................................40 
 
MYSQL FUNCTIONS..................................................................................................................................41
 

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->