Header ("Content-type:text/html;charset=utf-8");
$conn = mysql_connect (' localhost ', ' root ', ');//linked server (non-persistent)
if (! $conn) {
Echo ' ';
Die (' ERROR: '. mysql_error ());
}else{
Echo ' ';
Echo ' Linked server: '. $conn;
}
$db = mysql_select_db (' Test ', $conn);//Select Database
if (! $db) {
Echo ' ';
Die (' ERROR: '. mysql_error ());
}else{
Echo ' ';
echo ' link database: '. $db;
}
/*
mysql_query () returns a resource identifier only for Select,show,explain or DESCRIBE statements, or FALSE if the query is executed incorrectly.
For other types of SQL statements, mysql_query () returns TRUE on successful execution and returns FALSE on error.
A return value other than FALSE means that the query is legitimate and can be executed by the server. This does not indicate any information about the number of rows affected or returned. It is possible that a query executed successfully but did not affect or return any rows.
*/
$sql = "SELECT * from user";
$result = mysql_query ($sql, $conn);//executes a MySQL query that automatically reads and caches the recordset. If you want to run a non-cached query, use Mysql_unbuffered_query ().
Echo ' ';
echo ' Query result set: '. $result;//return Resource Identifier
Echo ' ';
Print_r (Mysql_fetch_array ($result, MYSQL_ASSOC));//function gets a row from the result set as an associative array
Echo ' ';
Print_r (Mysql_fetch_array ($result, Mysql_num));//function gets a row from the result set as a numeric array
Echo ' ';
Print_r (Mysql_fetch_array ($result));//function takes a row from the result set as an associative array and a numeric array, and the Mysql_fetch_row () function takes a row from the result set as a numeric array
/*
The Mysql_fetch_array () function takes a row from the result set as an associative array, or as a numeric array, or both
Returns an array based on the rows obtained from the result set, or False if there are no more rows.
*/
Echo ' ';
Echo '
'; while ($row = Mysql_fetch_array ($result)) {echo "
"; echo "
" . $row [' FirstName ']. " | "; echo "
" . $row [' LastName ']. " | "; echo "
" . $row [' Age ']. " | "; echo "
" . $row [' Hometown ']. " | "; echo "
" . $row [' Job ']. " | "; echo "
"; } Echo '
';
Echo ' ';
Echo ' Closes the non-persistent MySQL connection: '. Mysql_close ();
$name = Array (' fruits ' = = Array (' Orange ', ' banana ', ' apple '),
' Veggie ' = = Array (' carrot ', ' collard ', ' pea '));;
Echo ' ';
Print_r ($name [' Fruits '][1]);
Echo ' ';
echo count ($name);//calculates the number of cells in an array or the number of attributes in an object
Echo ' ';
/*
Symbol "--" means the function and member variables of the calling class
*/
Class classname{
function Funname () {
echo "DGGDGDGD";
}
}
$classOne = new ClassName ();
$classOne->funname ();
Echo ' ';
$i = 0;
do{
$i + +;
echo "The number is". $i. "
";
}
while ($i <5);
http://www.bkjia.com/PHPjc/325737.html www.bkjia.com true http://www.bkjia.com/PHPjc/325737.html techarticle header ("Content-type:text/html;charset=utf-8"), $conn = mysql_connect (' localhost ', ' root ', ');//linked server (non-persistent) if ( ! $conn) {echo ' hr/'; die (' ERROR: '. mysql_error ());} El ...