header("Content-Type:text/html;charset=UTF-8");
$conn = mysql_connect('localhost','root','');//Linked server (non-permanent)
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 'Linked database:'.$db;
}
/*
mysql_query() returns a resource identifier only for SELECT, SHOW, EXPLAIN or DESCRIBE statements, if Returns FALSE if the query is not executed correctly.
For other types of SQL statements, mysql_query() returns TRUE when executed successfully and FALSE when an error occurs.
A return value other than FALSE means the query is valid and can be executed by the server. This does not say anything about the number of rows affected or returned. It's possible that a query executed successfully but did not affect or return any rows.
*/
$sql="SELECT * FROM user";
$result = mysql_query($sql,$conn);//Execute a MySQL query, this function automatically reads and cache. To run uncached queries, use mysql_unbuffered_query().
echo '
';
echo 'Query result set:'.$result;//Return resource identifier
//echo '
';
//print_r(mysql_fetch_array($result,MYSQL_ASSOC));//The function gets a row from the result set as an associative array
//echo '
';
//print_r(mysql_fetch_array($ result,MYSQL_NUM));//The function gets a row from the result set as a numeric array
//echo '
';
//print_r(mysql_fetch_array($result));//The function is from Get a row from the result set as an associative array or a numeric array. The mysql_fetch_row() function gets a row from the result set as a numeric array. , or both
Returns an array based on the rows taken from the result set, or false if there are no more rows.
*/
echo '
';
echo '
';
while( $row = mysql_fetch_array($result)){
echo "";
echo "" . $row['FirstName'] . " | ";
echo "" . $row['LastName'] . " | ";
echo "" . $row['Age'] . " | ";
echo "" . $row['Hometown'] . " | ";
echo "" . $row['Job'] . "< ;/td>"; echo " |
";
}
echo '
';
echo '
';
echo 'Close 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);//Calculate the number of cells in the array or the number of attributes in the object
echo '
';
/*
The symbol "->" means: calling the functions and member variables of the class
*/
class className{
function funName( ){
echo "dggdgdgd";
}
}
$classOne = new className();
$classOne->funName();
echo '< ;hr/>';
$i=0;
do{
$i++;
echo "The number is " . $i . "
";
}
while ($i<5);
http://www.bkjia.com/PHPjc/325737.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325737.htmlTechArticleheader("Content-Type:text/html;charset=UTF-8"); $conn = mysql_connect( 'localhost','root','');//Linked server (non-permanent) if(!$conn){ echo 'hr/'; die('error:'.mysql_error()); }el.. .