Eyad Hainey Eyad Hainey

Connect MySQL to PHP

After building and structuring your SQL database, and you want to display them on your PHP website, you need to start  a connection form that links the website to your local host PhpMyAdmin (MySQL).

Localhost: keep it if the SQL database is on the same host
mysql_user: is your login username to PhpMyAdmin
mysql_password: your PhpMyAdmin password

[codebox 1]

after this point, you can start calling tables or databases in your MySQL host this way:

[codebox 2]

Result: is the calling back query.
mysql_query: SQL query should be written between (” “); .
TABLE_NAME: is that selected table and can be ordered by the Table_id
DESC: descending ordering or ASC ascending ordering.
While: loop to bring information from the selected table in the database
$row: calling back function.
mysql_fetch_array: array fetch.
echo: is a results displayer and bounce back requested attributes
Username, Email, DOB: attributes from TABLE_NAME

 

If you have your own Style/CSS, and just want to embed Php in it, use the following:

[codebox 3]

It is just like the previous code, just a wrapper around a selected area to display your SQL tables in them, ending the code with “?>” and starting it with “<?” and close the connection with ” }?>

 

Thanks

Eyad Hainey


Leave a Reply

Your email address will not be published. Required fields are marked *