Home  >  Article  >  php教程  >  php中选择什么接口(mysql、mysqli)访问mysql

php中选择什么接口(mysql、mysqli)访问mysql

WBOY
WBOYOriginal
2016-06-06 20:32:08823browse

我们知道,mysqli是PHP 5中新提供的MySQL接口,此接口使用了面向对象的思想。使用mysqli接口的代码可读性更强,其执行效率比mysql接口高

我们知道,mysqli是PHP 5中新提供的MySQL接口,此接口使用了面向对象的思想。使用mysqli接口的代码可读性更强,其执行效率比mysql接口高。而且mysqli提供了一个能够一次执行多个SQL语句的multi_query()函数。但是,mysqli接口只支持PHP 5和MySQL 4.1之后的版本。

query()函数一次只能执行一条SQL语句,而multi_query()函数可以一次执行多个SQL语句。
如果第一个SQL语句执行正确,那么multi_query()函数返回true,否则返回false。
通过store_result()函数获取multi_query()函数执行查询的记录。一次只能获取一个SQL语句的执行结果。
通过next_result()函数判断下一个SQL语句的结果是否存在,如果存在,返回true。

示例:
代码如下:
$sql="select * from score; select * from student";
$rs=$connection->multi_query($sql);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn