mysqli (MySQL Improved)

The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer

The mysqli extension has a number of benefits, the key enhancements over the mysql extension being:

– Object-oriented interface

– Support for Prepared Statements

– Support for Multiple Statements

– Support for Transactions

– Enhanced debugging capabilities

– Embedded server support

$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}

$res = $mysqli->query("SELECT 'choices to please everybody.' AS _msg FROM DUAL");
if (!$res) {
die('There was an error running the query [' . $db->error . ']');
}
$row = $res->fetch_assoc();
echo $row['_msg'];

echo 'Total results: ' . $res->num_rows;

$statment = $db->prepare("SELECT `name` FROM `users` WHERE `username` = ? and `age` = ?");
$statement->bind_param('si', $name, $age);
$statement->execute();
$result = $statement->get_result();
while($row = $result->fetch_array(MYSQLI_ASSOC)){
}

In bind param, first parameter denotes the types “s for string, i for integer, d for decimal, etc)

http://codular.com/php-mysqli

Leave a Reply