Mysqli is a feature that is only available after php5, and friends who do not have extensions open up your php.ini configuration file.
Look for the following statement:; Extension=php_mysqli.dll modify it to: Extension=php_mysqli.dll.
There are many new features and advantages relative to MySQL
(1) Support for local binding, preparation (prepare) and other syntax
(2) Error code to execute SQL statement
(3) Simultaneous execution of multiple SQL
(4) The method of object-oriented calling interface is also provided.
Below one by one uses the PHP instance to carry on the MYSQLI database connection!
Use method One: using traditional process-oriented approach
The PHP code is as follows:
Copy Code code as follows:
<?php
$connect = Mysqli_connect (' localhost ', ' root ', ', ', ' volunteer ') or Die (' Unale to connect ');
$sql = "SELECT * from Vol_msg";
$result = Mysqli_query ($connect, $sql);
while ($row = Mysqli_fetch_row ($result)) {
echo $row [0];
}
?>
Use method Two: Invoke an interface using an object-oriented method (recommended)
Look at the PHP code as follows:
Copy Code code as follows:
<?php
Create the object and open the connection, and the last parameter is the selected database name
$mysqli = new mysqli (' localhost ', ' root ', ' ', ' volunteer ');
Check if the connection was successful
if (Mysqli_connect_errno ()) {
Note Mysqli_connect_error () new features
Die (' Unable to connect! '). Mysqli_connect_error ();
}
$sql = "SELECT * from Vol_msg";
Execute the SQL statement, fully object-oriented
$result = $mysqli->query ($sql);
while ($row = $result->fetch_array ()) {
echo $row [0];
}
?>
The above two PHP instances run the same results, you can clearly see the advantages of using the Mysqli class object to build a database connection!
Insert and modify records I don't have to say, just change the SQL statement on the line, the next one I will speak prepare interface features!