tags:

views:

41

answers:

3

I was wondering if the older mysql_* functions provided with php will work with a mysqli connection.

+2  A: 

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.

Alan Geleynse
mysqli also provides function aliases to the OO interface. Under the hood both mysqli and mysql use the new mysqlnd, which is a driver written in native php instead of just binding to libmysql.
Gordon
Ah, good to know, I hadn't seen those. The basic answer is still correct though, you cannot use the old functions with the new connection type.
Alan Geleynse
A: 

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.

Slokun
A: 

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.

Gordon