PHP Connect and manipulate MySQL database

Source: Internet
Author: User

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

Related Article

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.