Home >Backend Development >PHP Tutorial >A brief introduction to the MYSQLI_PHP tutorial introduced in PHP5
In the newly downloaded PHP5, you will find an extra mysqli.dll. What is it used for? Let me briefly introduce it:
mysqli.dll is PHP’s extended support for the new features of mysql. In PHP5, it can be loaded in php.ini, as shown below:
, interface, ingenious, incompatible or incomplete (the extension is still under development, Because MYSQL4.1 and MYSQL5 have not been officially launched and are still under development, new features have not been fully implemented)
The specific goals that mysqli wants to achieve are:
-Easier maintenance
-Better compatibility
-Backward Compatibility
mysql (referring to the module in PHP) has developed into a mess and needs to be reorganized. At the same time, it is necessary to keep up with the development pace of MYSQL (DBMS), add support for new features, and adapt to future versions of MYSQL (DBMS). So mysqli.dll was born
Features of mysqli.dll:
- Can be used in the same way as mysql.dll
- Supports OO interface, simply call
- Supports MYSQL4.1 introduced New features
-Advanced connection options can be set through related functions such as mysqli_init()
Mysqli usage example:
1. The same method as the previous mysql.dll:
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'user ', /* The user to connect as */
'password', /* The password to use */
'world'); /* The default table to query */
if (!$ link) {
printf("Can't connect to MySQL Server. Errorcode: %sn", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
print("Very large cities are:n");
/* Fetch the results of the query */
while( $row = mysqli_fetch_assoc($result) ){
printf("%s (%s)n", $row['Name'], $row[' Population']);
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
Output result:
Very large cities are:
Mumbai (Bombay) (10500000)
Seoul (9981619)
São Paulo (9968485)
Shanghai (9696300)
Jakarta (9604900)
2. Use the built-in OO interface to call:
/* Connect to a MySQL server */
$mysqli = new mysqli('localhost', 'user', 'password', 'world ');
if (mysqli_connect_errno()) {
printf("Can't connect to MySQL Server. Errorcode: %sn", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = $mysqli->query('SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
print("Very large cities are:n");
/* Fetch the results of the query */
while( $row = $result->fetch_assoc() ){
printf("%s (%s)n" , $row['Name'], $row['Population']);
}
/* Destroy the result set and free the memory used for it */
$result->close() ;
}
/* Close the connection */
$mysqli->close();
?>
New features supported include: Bound Parameters, Bound Results et al.
If you are interested, you can go directly to the original English: