PHP Basic Knowledge Review _php Tutorial

Source: Internet
Author: User
Header ("Content-type:text/html;charset=utf-8");
$conn = mysql_connect (' localhost ', ' root ', ');//linked 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 a resource identifier only for Select,show,explain or DESCRIBE statements, 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 gets a row from the result set as a numeric array
Echo ' ';
Print_r (Mysql_fetch_array ($result));//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

/*
The Mysql_fetch_array () function takes a row from the result set as an associative array, or as a numeric array, or both
Returns an array based on the rows obtained from the result set, or 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 attributes in an object

Echo ' ';
/*
Symbol "--" means the function and member variables 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);

http://www.bkjia.com/PHPjc/325737.html www.bkjia.com true http://www.bkjia.com/PHPjc/325737.html techarticle header ("Content-type:text/html;charset=utf-8"), $conn = mysql_connect (' localhost ', ' root ', ');//linked server (non-persistent) if ( ! $conn) {echo ' hr/'; die (' ERROR: '. mysql_error ());} El ...

  • Related Article

    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.