- PHP's MySQL Extension (old one)
- PHP's mysqli Extension (current using)
- PHP Data Objects (PDO)
I´ll talk about the second one: mysqli.
mysqli means "MySQL improved extension".
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
As well as the object-oriented interface the extension also provides a procedural interface.
Procedural interface
$mysqli = mysqli_connect("example.com", "user", "password", "database");
if (mysqli_connect_errno($mysqli)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$res = mysqli_query($mysqli, "SELECT 'A world full of ' AS _msg FROM DUAL");
$row = mysqli_fetch_assoc($res);
echo $row['_msg'];
Object-oriented interface
$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");
$row = $res->fetch_assoc();
echo $row['_msg'];
http://php.net/manual/en/mysqli.quickstart.dual-interface.php
Nenhum comentário:
Postar um comentário