Mysqli 简明教程
MySQLi - Introduction
MySQLi 是 PHP 中 MySQL API 的一个扩展,从 PHP 5.0 开始使用。它也被称为改良的 MySQL 扩展。MySQLi 背后的动机是要利用 MySQL 4.1.3 及更高版本中可用新功能的优势。它提供了比 MySQL 扩展有许多优势。
MySQLi is an extension to MySQL API available in PHP and is introduced from PHP 5.0 onwards. It is also known as MySQL improved extension. Motivation behind MySQLi was to take advantage of new features available in MySQL 4.1.3 onwards. It provides numerous benefits over MySQL extension.
-
MySQL provides an object oriented interface. It provides both object oriented and procedural approach to handle database operations.
Object Oriented Interface
<?php
$mysqli = mysqli_connect("localhost", "user", "password", "database-name");
$result = mysqli_query($mysqli, "SELECT 'Welcome to MySQLi' AS _msg FROM DUAL");
$row = mysqli_fetch_assoc($result);
echo $row['_msg'];
?>
Procedural Approach
<?php
$mysqli = new mysqli("localhost", "user", "password", "database-name");
$result = $mysqli→query("SELECT 'Welcome to MySQLi' AS _msg FROM DUAL");
$row = $result→fetch_assoc();
echo $row['_msg'];
?>
-
MySQLi supports prepared statments.
-
MySQLi supports multiple statments.
-
MySQLi supports transactions.
-
MySQLi provides enhanced debugging capabilities.