//mysql_connect (' localhost ', ' root ', ');$link=mysql_connect(' 127.0.0.1:3306 ', ' root ', ') orExit(' Failed to connect to database ');//nowmysql_select_db(' Pg37 ',$link) or die(' no corresponding database ');//$sql= ' Select *from t_student ';//mysql_query(' Set names UTF8 ');//Set character sets$infos=mysql_query($sql);//return value, Boolean, Resource$arr=Array();if($infos){ while($info=Mysql_fetch_row($infos,Mysql_both)) { //Mysql_both associated arrays also have indexed arrays Array_push($arr,$info); }}Mysql_free_result($infos);//Freeing ResourcesMysql_close($link);//To close a database connection
Mysqli
//mysql_connect (' localhost ', ' root ', ');$link=Mysqli_connect(' 127.0.0.1:3306 ', ' root ', ') orExit(' Failed to connect to database ');//nowmysqli_select_db($link, ' pg37 ') or die(' no corresponding database ');////mysql_query (' Set names UTF8 ');//setting Character set$infos=Mysqli_query($link, ' Select *from t_student ');//return value, Boolean, Resource$arr=Array();if($infos){ while($info=Mysqli_fetch_row($infos)){ //Mysql_both Constants Array_push($arr,$info); }}Var_dump($arr);Mysqli_free_result($infos);//Freeing ResourcesMysqli_close($link);//To close a database connection
Upgrade version Mysqli
//Connect to database//Initialize a database connection object$mysqli=Mysqli_init();if(!$mysqli) { die(' Initialization of connection object failed ... ');}//sets the properties of the Mysqli object, whether it is automatically committed, and 1 is auto-committed. The default value is 1,0 need to be submitted manuallyif(!mysqli_options($mysqli, Mysqli_init_command, ' SET autocommit = 1 ')) { die(' failed to set autocommit mode ... ');}//sets the properties of the Mysqli object, which automatically stops if there is no execution action for more than 5 secondsif(!mysqli_options($mysqli, Mysqli_opt_connect_timeout, 5)) { die(' failed to set connection failure time for database ... '));}if(!Mysqli_real_connect($mysqli, ' localhost ', ' root ', ' ', ' pg37 ', 3306)) { die(' Connection failed '.Mysqli_connect_errno() . ‘) ‘ .Mysqli_connect_error());}//sending SQL statements to the database side and executing the returned resultsMysqli_set_charset ($mysqli, ' UTF8 ');//$char = Mysqli_character_set_name ($mysqli);//var_dump ($char);$infos=Mysqli_query($mysqli, ' select * from T_student ');//Var_dump ($infos);//Process return value results$arr=Array();if($infos){ //MYSQLI_NUM=1/2/3; while($info=Mysqli_fetch_array($infos,mysqli_num)) { Array_push($arr,$info); }//The data result set is processed and the corresponding memory space is freed. Mysqli_free_result($infos);}Var_dump($arr);//To close a database connectionMysqli_close($mysqli);
MySQL Basic function library