Header ("Content-type:text/html;charset=utf-8"); $conn = mysql_connect (' localhost ', ' root ', ');//link 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 only one resource identifier for the Select,show,explain or DESCRIBE statement, 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 takes a row from the result set as a numeric array//echo '
‘; Print_r (Mysql_fetch_array ($result));//The 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/* Mysql_fetch The _array () function takes a row from the result set as an associative array, or a numeric array, or both returns an array based on the rows taken from the result set, and returns False if there are no more rows. */Echo '
‘; Echo '
‘; while ($row = Mysql_fetch_array ($result)) {echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "";} Echo '
" . $row [' FirstName ']. " |
" . $row [' LastName ']. " |
" . $row [' Age ']. " |
" . $row [' Hometown ']. " |
" . $row [' Job ']. " |
‘; 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 properties in an object echo '
‘; /* symbol "--" means the function and member variable 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);
PHP Basics Review