<?PHP//database Connection file: link.php$link=mysql_connect("localhost", "root", "" ");if(Mysql_errno()){ Exit("Database connection failed.")Mysql_error());}if(!mysql_select_db("Jkxy")){ Exit("Select Database Failed");} Mysql_set_charset ("UTF8");? ><?PHP//database operation file: user.phpinclude_once('./link.php ');$sql= "SELECT * from User";$res=mysql_query($sql);//mysql_query ($sql) What data is returned, what is the data typeEcho mysql_num_rows($res);//returns the number of record bars in the result setEcho"<br/>";/*Mysql_num_row ($res); Gets the number of record bars in the result set when $SQL is a query statement, the result set resource type is returned, and the data in the result set is obtained PHP provides us with four functions mysql_fetch_array (); Returns the indexed and associated mixed array mysql_fetch_assoc (); Returns an associative array in which the index of the array is the field name, and the value of the array corresponds to one record for each field in the record. Mysql_fetch_row (); Returns an indexed array of mysql_fetch_object (); Returns an object other functions: Mysql_affected_rows (); The effect of the number of rows is unique, and the result set is a unique mysql_insert_id (); Gets the Idmysql_free_result ($res) of the inserted row; Releases the result data table saved at execution mysql_close ($link); To close a database connection*/if($res){//Associative Arrays/*While ($row = Mysql_fetch_assoc ($res)) {echo "{$row [' id ']}-{$row [' username ']}-{$row [' pwd ']}-{$row [' Email ']}-{$ row[' Tel ']-{$row [' Score ']} "; echo" *///index Array, the value of each subscript in the array assigned to the variable in list () while(List($id,$username,$pwd,$email,$tel,$score) =Mysql_fetch_row($res)){Echo"{$id}-{$username}-{$pwd}-{$email}-{$tel}-{$score}";Echo";}Mysql_free_result($res);}Mysql_close($link);?>
PHP Connect and manipulate MySQL database