Basic Database Operations

Source: Internet
Author: User

Lamp architecture refers to: Linux, Apache, MySQL, PHP 1. Whether to install MySQL extension if (function_exists (' mysql_connect ')) {echo ' MySQL extension has been installed ';} 2. Establish the connection header ("Content-type:text/html;charset=utf-8");//set character Set $con = Mysql_connect ($host, $user, $pass);     3. Select Database $flag =mysql_select_db ("dbname") 4. Close Connection mysql_close ($con); $con for Connection object 5. $query =mysql_query ("SQL"), mysql_query ("Set names UTF8") if ($query) to determine if the query statement is correct SQL: sql inserted or searched, all SQL statements are executed through mysql_query.When the executed statement is a SELECT statement, if execution succeeds, the resource identifier 6.echo mysql_error () is returned with the print error log four fetch function 1. mysql_fetch_row ()Gets and displays the data, producing a indexed Array$query =mysql_query ("SELECT * from Student");p rint (Mysql_fetch_row ($query)); Returns the first data while ($row =mysql_fetch_row ($query)) {Print_r ($row);} 2. mysql_fetch_array (), an indexed array and an associative array are generated$query =mysql_query ("SELECT * from Student"), $array =mysql_fetch_array ($query, MYSQL_ASSOC); the second parameter: MYSQL_ASSOC: Generate associative array Mysql_num: produces an indexed array of Mysql_both: default, resulting in an index and associative array 3.MYSQL_FETCH_ASSOC () consistent with mysql_fetch_array ($query, MYSQL_ASSOC) function; 4.mysql_fetch_object ()// Gets a result set object while ($row =mysql_fetch_object ($query)) {echo $row->name;}          5.mysql_num_rows (), gets the number of rows in the result set $query =mysql_query ("SELECT * from student"); $rowCount =mysql_num_rows ($query); 6.mysql_result ($query, $rownum, $offset), gets a column of a row in the result set three parameters: $query: Resource Identifier $rownum: number of rows $offset: The offset of the field name or column 7.mysql_ Affected_rows ($con), gets the number of rows affected by the previous operation

Basic Database Operations

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.