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