PHP and MySQL - La Salle University

Download Report

Transcript PHP and MySQL - La Salle University

PHP and MySQL
Get data from the Northwind Product
table and displaying it using PHP
Have a PHP page, start the table in
HTML, then start a PHP section
Set up PHP variables to connect to database.
-Since the page and database are both on the gamma
the $host variable is set to localhost
-The other variables are the MySQL username and
password and the name of your database
Use the mysql_connect method to connect to
MySQL.
Remember page and MySQL database are both
on gamma.
The die method writes a messages and quits –
used if something goes wrong.
Use the mysql_select_db method
to choose your database.
It’s case sensitive!
The $sql variable is set to an SQL
query. You can cheat here and let
PHPMyAdmin generate the PHP code
for you.
$i is for counting
The while loop processes the records from the query
The individual fields resulting from the query are
accessed using the variable $row[] – the first field has
an index 0, etc.