Define (' dbhost ', ' localhost ');
Define (' DBUSER ', ' root ');
Define (' dbpd ', ');
Define (' MYDB ', ' Java ');
Two forms of database operations are only 1. Object-Oriented Programming
@ $mysqli =new mysqli (dbhost,dbuser,dbpd,mydb);
$mysqli->select_db (dbname); You can use this function to select a database
$name = "Qweqwe";
$query = "SELECT * from User WHERE username=". "' $name ' ";
$result = $mysqli->query ($query);
$row = $result->fetch_row ();//equivalent to the following method
$num _results=mysqli_num_rows ($result);//Returns the number of rows
for ($i =0; $i < $num _results; $i + +) {
$row = $result 2->fetch_assoc ();//Get the value of each bar in turn
}
$result->free ();//Release resources
$mysqli->close ();//Close database connection
Database Operations 2. Process-oriented programming
$mysqli 2=mysqli_connect (DBHOST,DBUSER,DBPD,MYDB);//returns a resource rather than an object
mysqli_select_db ($mysqli 2, "Sbname"); Need to pass in Mysqli2 this resource to select the database note: In process-oriented
$name 2= "Qweqwe";
$query 2= "SELECT * from User WHERE username=". "' $name 2 ' ";
$result 2=mysqli_query ($mysqli 2, $query 2);
$row 2= $mysqli _fetch_row ($result 2);//equivalent to the following method
$num _results2=mysqli_num_rows ($result 2);//Returns the number of rows
for ($i =0; $i < $num _results2; $i + +) {
$row 2= $mysqli _fetch_assoc ($result 2);
}
The optional second parameter in mysql_fetch_array () result_type is a constant that accepts the following values:Mysql_assoc, Mysql_num,and MySQL _both. This feature is for PHP 3.0.7 New Plus. The default value for this parameter is Mysql_both.
If you use Mysql_both, you will get an array that contains both associative and numeric indexes. With Mysql_assoc, only the associated index (as in Mysql_fetch_assoc () ) is used, and the mysql_num only gets the numeric index (as in mysql_fetch_row ( ) .
Object-oriented and process-oriented connection database