PHP Summary 8--mysql function library, add and revise

Source: Internet
Author: User

8.1 MySQL Function library

PHP functions. Functions used in PHP to operate the MySQL function library

Common functions

Mysql_connect ("Host name/IP", "username", "password")---> Build php connection to MySQL, return resources---->

Mysql_error () returns the text error message for the previous MySQL operation

@ ERROR Suppressor

In general, Mysql_connect and Mysql_error () are used together as shown in the following way:

<? PHP $link [Email protected] mysql_connect  die ("Connection Error".) Mysql_error ()); // Die () outputs the contents of parentheses and terminates the subsequent program ?>

mysql_select_db ("Database name", $link)//Select database equivalent to use database name

mysql_query () sends a SQL command to the database

If Chinese is not displayed properly, mysql_query (set names UTF8)

Mysql_affected_rows () Gets the previous SQL statement, returning the number of rows affected. Mainly on the deletion and modification of the effect.

Mysql_close () Close a link to the database

Mysql_fetch_array (Result set, Parameter 2) returns a record from the result set (it is a mixed array, that is, both an indexed array and an associative array)

Parameter 2 can be: Mysql_assoc associative array

Mysql_num indexed arrays

Mysql_both mixed Array (default)

MYSQL_FETCH_ASSOC ($result) equivalent to Mysql_fetch_array ($result, MYSQL_ASSOC)

Mysql_fetch_row ($result) equivalent to Mysql_fetch_array ($result, Mysql_num)

Mysql_num_row () Gets the number of record bars in the result set after the SELECT statement is executed.

8.2 MySQL production user's additions and deletions change

 1  //  Execute SQL statement: SQL statements exist as strings in PHP  2  3  Span style= "COLOR: #008000" >// 4   $sql  = "INSERT into users (name, PWD, gender, tel, emails) values (' Zhangsan ', ' 123 ', ' 1 ', ' 15811032222 ', ' [email  Protected] " 5  //  change  6   $sql  = "Update users set Name= ' Lisi ' Where id=0 '  7  //  delete  8   $sql  = "Delete from users where id=0 ";

Query for MySQL production user

1 Header("Content-type:text/html;charset=utf-8");2 $link[Email protected]mysql_connect("localhost", "root", "") or die("Connection Error".)Mysql_error());3 mysql_select_db("Test",$link);4 mysql_query("Set Names UTF8");5 $sql= "Select *from users"; Can write various queries6 $result=mysql_query($sql); Execute Query statement, return resource (result set)7  while($rs=Mysql_fetch_assoc($result)){8     Print_r($rs);9     Echo"<br/>";Ten}

PHP Summary 8--mysql function library, add and revise

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.