PHP Basics Review

Source: Internet
Author: User
Tags mysql query php basics

Header ("Content-type:text/html;charset=utf-8"); $conn = mysql_connect (' localhost ', ' root ', ');//link server (non-persistent) if (! $conn) {echo '

‘; Die (' ERROR: '. mysql_error ()); }else{Echo '

‘; Echo ' Linked server: '. $conn; } $db = mysql_select_db (' Test ', $conn);//Select Database if (! $db) {echo '

‘; Die (' ERROR: '. mysql_error ()); }else{Echo '

‘; echo ' link database: '. $db; }/* mysql_query () returns only one resource identifier for the Select,show,explain or DESCRIBE statement, or FALSE if the query is executed incorrectly. For other types of SQL statements, mysql_query () returns TRUE on successful execution and returns FALSE on error. A return value other than FALSE means that the query is legitimate and can be executed by the server. This does not indicate any information about the number of rows affected or returned. It is possible that a query executed successfully but did not affect or return any rows. */$sql = "SELECT * from user"; $result = mysql_query ($sql, $conn);//executes a MySQL query that automatically reads and caches the recordset. If you want to run a non-cached query, use Mysql_unbuffered_query (). Echo '

‘; echo ' Query result set: '. $result;//return Resource Identifier//echo '

‘; Print_r (Mysql_fetch_array ($result, MYSQL_ASSOC));//function gets a row from the result set as an associative array//echo '

‘; Print_r (Mysql_fetch_array ($result, Mysql_num));//function takes a row from the result set as a numeric array//echo '

‘; Print_r (Mysql_fetch_array ($result));//The function takes a row from the result set as an associative array and a numeric array, and the Mysql_fetch_row () function takes a row from the result set as a numeric array/* Mysql_fetch The _array () function takes a row from the result set as an associative array, or a numeric array, or both returns an array based on the rows taken from the result set, and returns False if there are no more rows. */Echo '

‘; Echo '

‘; while ($row = Mysql_fetch_array ($result)) {echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "";} Echo '

" . $row [' FirstName ']. " " . $row [' LastName ']. " " . $row [' Age ']. " " . $row [' Hometown ']. " " . $row [' Job ']. "

‘; Echo '

‘; Echo ' Closes the non-persistent MySQL connection: '. Mysql_close (); $name = Array (' fruits ' = = Array (' Orange ', ' banana ', ' apple '), ' veggie ' = = Array (' carrot ', ' collard ', ' pea '));; Echo '

‘; Print_r ($name [' Fruits '][1]); Echo '

‘; echo count ($name);//calculates the number of cells in an array or the number of properties in an object echo '

‘; /* symbol "--" means the function and member variable of the calling class */class classname{function Funname () {echo "DGGDGDGD";}} $classOne = new ClassName (); $classOne->funname (); Echo '

‘; $i = 0; do{$i + +, echo "The number is". $i. "
";} while ($i <5);

PHP Basics Review

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.