Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 8

Your datasource

 MySQL is a database. A database defines a


structure for storing information.
 In a database, there are tables. Just like

HTML tables, database tables contain rows,


columns, and cells.
 Databases are useful when storing

information categorically. A company may


have a database with the following tables:
"Employees", "Products", "Customers" and
"Orders".
 $con = mysql_connect(servername,
username, password);
 mysql_close($con);
<?php
$con = mysql_connect("localhost", "peter",
"abc123");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
 A database must be selected before a table
can be created. The database is selected
with the mysql_select_db() function.
 mysql_select_db("my_db", $con);
 To get PHP to execute an SQL statement we
must use the mysql_query() function.
 $result = mysql_query("SELECT * FROM

person");
 Use mysql_fetch_array() function to get the
query result as an array.
 $result = mysql_query(‘SELECT * FROM

person’);
 while($row = mysql_fetch_array($result))

{ echo $row['FirstName'] . " " .


$row['LastName']; echo "<br />"; }

You might also like