php连接mysql的驱动支持 请使用mysqlnd php官方原生驱动。编译参数中需要加如下 ./configure --with-mysql=mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \ 三种(mysql,mysqli,pdo-mysql)php连接 mysql api接口都采用mysqlnd驱动。 php连接
请使用mysqlnd php官方原生驱动。编译参数中需要加如下
./configure --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \
三种(mysql,mysqli,pdo-mysql)php连接 mysql api接口都采用mysqlnd驱动。
php官方推荐使用?mysqli?和?PDO_MySQL
php连接mysql的三种api示例
<?php
// mysqli
$mysqli = new mysqli("example.com", "user", "password", "database");
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $result->fetch_assoc();
echo htmlentities($row['_message']);
// PDO
$pdo = new PDO('mysql:host=example.com;dbname=database', 'user', 'password');
$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);
// mysql
$c = mysql_connect("example.com", "user", "password");
mysql_select_db("database");
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = mysql_fetch_assoc($result);
echo htmlentities($row['_message']);
?>PHP中三种主要的MySQL连接方式的功能:
| PHP的mysqli扩展 | PDO (使用PDO MySQL驱动和MySQL Native驱动) | PHP的mysql扩展 | |
|---|---|---|---|
| 引入的PHP版本 | 5.0 | 5.0 | 3.0之前 |
| PHP5.x是否包含 | 是 | 是 | 是 |
| MySQL开发状态 | 活跃 | 在PHP5.3中活跃 | 仅维护 |
| 在MySQL新项目中的建议使用程度 | 建议 – 首选 | 建议 | 不建议 |
| API的字符集支持 | 是 | 是 | 否 |
| 服务端prepare语句的支持情况 | 是 | 是 | 否 |
| 客户端prepare语句的支持情况 | 否 | 是 | 否 |
| 存储过程支持情况 | 是 | 是 | 否 |
| 多语句执行支持情况 | 是 | 大多数 | 否 |
| 是否支持所有MySQL4.1以上功能 | 是 | 大多数 | 否 |
| ext/mysqli | PDO_MySQL | ext/mysql | |
|---|---|---|---|
| PHP version introduced | 5.0 | 5.1 | 2.0 |
| Included with PHP 5.x | Yes | Yes | Yes |
| Development status | Active | Active | Maintenance only |
| Lifecycle | Active | Active | Deprecated |
| Recommended for new projects | Yes | Yes | No |
| OOP Interface | Yes | Yes | No |
| Procedural Interface | Yes | No | Yes |
| API supports non-blocking, asynchronous queries with mysqlnd | Yes | No | No |
| Persistent Connections | Yes | Yes | Yes |
| API supports Charsets | Yes | Yes | Yes |
| API supports server-side Prepared Statements | Yes | Yes | No |
| API supports client-side Prepared Statements | No | Yes | No |
| API supports Stored Procedures | Yes | Yes | No |
| API supports Multiple Statements | Yes | Most | No |
| API supports Transactions | Yes | Yes | No |
| Transactions can be controlled with SQL | Yes | Yes | Yes |
| Supports all MySQL 5.1+ functionality | Yes | Most | No |
扩展阅读:
立即学习“PHP免费学习笔记(深入)”;
php连接mysql的驱动支持?http://www.php.net/manual/zh/mysqlnd.install.php
php连接mysql api ?mysqil?http://php.net/manual/zh/mysqli.overview.php
php连接mysql 三种api的选择?https://php.net/manual/zh/mysqlinfo.api.choosing.php
原文地址:php5.3.x 5.4.x 5.5.x 连接mysql数据库的三种方式以及所用驱动, 感谢原作者分享。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号