1 / 10

PHP and MySQL

PHP and MySQL. PHP for the Web, page 333-378. PHP and MySQL. MySQL Resource http://dev.mysql.com/doc/refman/5.5/en/ PHP – MySQL Resource http://us.php.net/manual/en/book.mysql.php http://us.php.net/manual/en/mysql.examples-basic.php Google “MySQL Create table”

kirsi
Télécharger la présentation

PHP and MySQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP and MySQL PHP for the Web, page 333-378

  2. PHP and MySQL MySQL Resource http://dev.mysql.com/doc/refman/5.5/en/ PHP – MySQL Resource http://us.php.net/manual/en/book.mysql.php http://us.php.net/manual/en/mysql.examples-basic.php • Google “MySQL Create table” • Google “PHP MySQL how to connect?”

  3. MySQL • Database server that is “almost free” • Integrated into Apache Web Server and PHP • PHP has many functions that can be used to interact with a MySQL server • Connect to a server • Query a server • Process query results

  4. PHP: How to connect to a MySQL Server $link = mysql_connect( server, user, password); mysql_select_db(database_name, $link); • mysql_connect return a “resource” • A resource is a special variable type, holding a reference to an external resource.

  5. Resources in PHP

  6. PHP: How to run a query $link = mysql_connect( server, user, password); mysql_select_db(database, $link); $result = mysql_query(“SELECT * FROM table”); • mysql_query returns a “resource” • In this case $result is a link to a mysql resource.

  7. PHP: mysql_fetch_array $q = “SELECT fname, lname FROM people WHERE userid = 65”; $result = mysql_query($q); $row = mysql_fetch_array($result); echo $row[‘fname’]. “ ”. $row[‘lname’]; Typically a query returns a table (a collection of rows). This query return one row.

  8. PHP: mysql_fetch_array $q = “SELECT fname, lname FROM people”; $result = mysql_query($q); $row = mysql_fetch_array($result); echo $row[‘fname’]. “ ”. $row[‘lname’]; This query returns more than one row. We only print the fname and lname of the first returned row

  9. PHP: mysql_fetch_array $q = “SELECT fname, lname FROM people”; $result = mysql_query($q); while ( $row = mysql_fetch_array($result) ) echo $row[‘fname’]. “ ”. $row[‘lname’]; mysql_fetch_array return null when it reaches the end of query results PHP interprets null as false

  10. PHP: How to get query results

More Related