PHP Basic Knowledge Review _php Basics

Source: Internet
Author: User
Tags mysql query
Header ("Content-type:text/html;charset=utf-8");


$conn = mysql_connect (' localhost ', ' root ', ');//linked server (not permanent)


if (! $conn) {


echo ' <hr/> ';


die (' ERROR: '. mysql_error ());


}else{


echo ' <hr/> ';


Echo ' linked server: '. $conn;


}





$db = mysql_select_db (' Test ', $conn);//Select Database


if (! $db) {


echo ' <hr/> ';


die (' ERROR: '. mysql_error ());


}else{


echo ' <hr/> ';


echo ' link database: '. $db;


}





/*


mysql_query () returns only a resource identifier for the Select,show,explain or DESCRIBE statement, FALSE if the query executes incorrectly.


for other types of SQL statements, mysql_query () returns TRUE on successful execution, and returns FALSE when an error occurs.


a return value of not FALSE means that the query is legitimate and can be executed by the server. This does not indicate any number of rows that are affected or returned. It is quite possible that a query execution succeeded but did not affect or return any rows.


*/


$sql = "SELECT * from user";


$result = mysql_query ($sql, $conn);//execute a MySQL query that automatically reads and caches the recordset. Use Mysql_unbuffered_query () if you want to run a non-cached query.


echo ' <hr/> ';


echo ' query result set: '. $result;//return Resource identifier


//echo ' <hr/> ';


//print_r (mysql_fetch_array ($result, MYSQL_ASSOC)); the//function takes one row from the result set as an associative array


//echo ' <hr/> ';


//print_r (mysql_fetch_array ($result, Mysql_num)); the//function takes one row from the result set as an array of numbers


//echo ' <hr/> ';


//print_r (mysql_fetch_array ($result)); the//function takes one row from the result set as an associative array and a numeric array, and the Mysql_fetch_row () function takes one row from the result set as an array of numbers





/*

The
mysql_fetch_array () function takes one row from the result set as an associative array, or an array of numbers, or both


returns the array generated from the rows obtained from the result set, or False if there are no more rows.


*/


echo ' <hr/> ';


Echo ' <table border= "1" cellspacing= "0" cellpadding= "5" > ";


while ($row = Mysql_fetch_array ($result)) {


echo "<tr>";


echo "<td>". $row [' FirstName ']. "</td>";


echo "<td>". $row [' LastName ']. "</td>";


echo "<td>". $row [' Age ']. "</td>";


echo "<td>". $row [' Hometown ']. "</td>";


echo "<td>". $row [' Job ']. "</td>";


echo "</tr>";


}


echo ' </table> ';





echo ' <hr/> ';


Echo ' closes a non-persistent MySQL connection: '. Mysql_close ();





$name = array (' Fruits ' => array (' orange ', ' banana ', ' apple '),


' veggie ' => array (' carrot ', ' collard ', ' pea '))


echo ' <hr/> ';


print_r ($name [' Fruits '][1]);


echo ' <hr/> ';


echo Count ($name);//Calculate the number of cells in an array or the number of properties in an object





echo ' <hr/> ';


/*

The
symbol "->" means that the function and member variables of the calling class are invoked


*/


Class classname{


function Funname () {


echo "DGGDGDGD";


}


}


$classOne = new ClassName ();


$classOne->funname ();





echo ' <hr/> ';


$i = 0;


do{


$i + +;


echo "The number is". $i. "<br/>";


}


while ($i <5);

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.