
application execute the php script to get the ‘member’ table in MySQL, then
parser the table to obtain the UID, password, and state. The following php
script shows how the php accesses MySQL:
<?
mysql_connect("localhost", "root", "root");
mysql_select_db("MyFamily");
$rows = mysql_query( "Select * from Member" );
if(!$rows)
echo "Executed Select error!";
else {
$num = mysql_num_rows($rows);
for ($J=0; $J<$num; $J++) {
while($field = mysql_fetch_field($rows))
$title[]="$field->name";
$row = mysql_fetch_row($rows);
for ($I=0; $I<count($row); $I++)
echo "$title[$I]\n$row[$I]\n ";
}
}
?>
The main functions in php script to access MySQL are:
mysql_connect("localhost", "root", "root")
Use mysql_connect to connect the MySQL, the ‘localhost’ is
PCM-7130, the two ‘root’ parameters is the name and password, use it login
to the MySQL.
mysql_select_db("MyFamily")
Use mysql_select_db to select the database in MySQL, the database can
be access after this command.
$rows = mysql_query( "Select * from Member" )
Use mysql_query to execute the SQL command, Use ‘Select * from
Member’ to query all rows in the ‘Member’ table.
$num = mysql_num_rows($rows)
Use mysql_num_rows to get a number of rows from a table, the result
$num is number of rows and the input $rows is the table.
$field = mysql_fetch_field($rows)
Use mysql_fetch_field to get the column information from an input
table ($rows) and return as an object.
$row = mysql_fetch_row($rows)
Use mysql_fetch_row to get a row form the table ($rows) to an
58