MySQL Basic function library

Source: Internet
Author: User

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.