ext/mysqli是PHP5和MySQL4.1起ext/mysql的替换器,i意思指的是:improved, interface, ingenious, incompatible or incomplete.


  • Easier maintainability The ext/mysql code base has become somewhat complex and messy. Major enhancements in the functionality of MySQL required that various feature sets be enabled or disabled based on the version of the client library. Other issues required that some features be disabled for particular operating systems.
  • Better compatibility The extension needed to conform more closely to the MySQL client library, so that future enhancements to the library could be supported more easily in PHP
  • Backwards compatibility Although the compatibility between ext/mysql and ext/mysqli is not perfect, effort was made to simplify porting applications from ext/mysql to ext/mysqli.

其除了类似ext/mysql中的函数,如:mysqli_query,mysqli_fetch_assoc,mysqli_close等,还支持Prepared Statements。采用Prepared Statements,可以使查询更为安全,更高效。对于大量的查询语句来说,效率确实要高得多,但是如果只是一两句查询的话,就体现不出来了。

下面是一个Prepared Statements的例子(来自PHP手册):

  1. $query = “INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)”;
  2. $stmt = $mysqli->prepare($query);
  3. $stmt->bind_param(“sss”, $val1, $val2, $val3);
  4. $val1 = ‘Stuttgart’;
  5. $val2 = ‘DEU’;
  6. $val3 = ‘Baden-Wuerttemberg’;
  7. /* Execute the statement */
  8. $stmt->execute();
  9. $val1 = ‘Bordeaux’;
  10. $val2 = ‘FRA’;
  11. $val3 = ‘Aquitaine’;
  12. /* Execute the statement */
  13. $stmt->execute();
  14. /* close statement */
  15. $stmt->close();

One thought on “ext/mysqli”

Leave a Reply

Your email address will not be published. Required fields are marked *