开发者

Using mysql_* functions with a mysqli connection

I was wondering if the older mysql_* funct开发者_开发问答ions provided with php will work with a mysqli connection.


No, the mysql_* functions were used only with the mysql driver.

There are new functions created for using with mysqli which you can read more about here.

The new method is object oriented instead of the old functional style.


The mysql extension uses resources for the link identifier:

There are two resource types used in the MySQL module. The first one is the link identifier for a database connection, the second a resource which holds the result of a query.

MySQLi does not provide any resources:

This extension has no resource types defined.

Consequently, when doing

$link = mysqli_connect('127.0.0.1', 'user', 'secret', 'test');
$result = mysql_query("SELECT 'it works' FROM dual", $link);

you will get

Warning: mysql_query() expects parameter 2 to be resource, object given

and $result will be NULL.


No, they won't, they're two entirely difference resources.

Unless you're trying to do a drop-in replacement of a MySQL connection with a MySQLIi connection, there's not much need for you to worry about this, unless you can't stand writing the i every time :-P

Remember though that you can still connect to newer MySQL databases with the mysql_* commands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜