Application of MySQL in PHP

Source: Internet
Author: User

Introduction: This is a detailed page for MySQL applications in PHP. It introduces the related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 330439 'rolling = 'no'>

1. Establish a link between PHP and MySQL

Modify PHP. ini to load MySQL components:

Extension = php_mysql.dll // remove the semicolon;

Extension_dir = ""

Link PHP to MySQL Functions

Mysql_connect ("host", "User Name", "password"); // enable the MySQL Link

Mysql_select_db ("Database Name", [LINK identifier]); // if the link identifier is not specifically declared, the default value is the last opened link.

@ Indicates a hidden error.

Or die is conditional display

Function opendb () {$ con = mysql_connect ("localhost", "root", "******"); If (! $ Con) {die ('could not connect :'. mysql_error ();} // or $ con = mysql_connect ("localhost", "root", "******") or die ('could not connect: '. mysql_error (); else {mysql_select_db ("9 lovetuan", $ con); mysql_query ("set names 'gb2312 '", $ con ); // avoid conversion of Chinese garbled characters return $ con ;}}

2. Execute SQL statements

Mysql_query (SQL statement, connection identifier );

Returns a result identifier upon success, and false upon failure.

$ SQL = "select * from test ";
$ Result = @ mysql_query ($ SQL, $ conn) or die (mysql_error ());

Differences between the two query functions array/row

Mysql_fetch_row (result );

Mysql_fetch_row is used to save a row of query results to an array. The subscript of this array starts from 0, and each array element corresponds to a field. You can obtain all query results through a loop.

Mysql_fetch_array (result );

The functions of mysql_fetch_array and mysql_fetch_row are basically the same, except that they can be indexed by Offset starting from 0 and domain name.

Both return all the domain values of the next row and save them to an array. If no row exists, false is returned.

Cyclic query result set

 
While ($ ROW = mysql_fetch_array ($ result) {echo $ row [name]. "<br>"; // echo $ row [0]. "<br> ";}

3. Other functions

Mysql_num_rows ($ result); // number of returned query results

Mysql_insert_id (); // returns the ID of the last INSERT command executed

Mysql_tablename ();//

Mysql_error (); // error message returned

Mysql_close (); // close the MySQL Link

More articles on "Application of MySQL in PHP"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/330439.html pageno: 11.

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.