Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Databases _ MySQL vs MySQLi

Posted by: Christian J Jul 3 2010, 03:39 PM

Is there any point in learning MySQL today, or should you go straight to MySQLi?

Posted by: Brian Chandler Jul 3 2010, 07:59 PM

What is MySQLi?

Remember that it's a good start to learn SQL, which you can use if you decide to use a different database engine, like the one you mentioned the other day (SQLite??)

So yes, there is a point in learning MySQL. It is not obvious that it's a question of going "straight to MySQLi" anymore than of going "straight to XHTML".

Posted by: Christian J Jul 4 2010, 05:31 AM

QUOTE(Brian Chandler @ Jul 4 2010, 02:59 AM) *

What is MySQLi?

http://www.php.net/manual/en/book.mysqli.php

I think the actual SQL is the same, but it seems you have to learn new related PHP functions, such as http://www.php.net/manual/en/mysqli.query.php instead of http://www.php.net/manual/en/function.mysql-query.php (it's not yet clear to me if all the old functions are replaced by new mysqli equivalents).

Posted by: Brian Chandler Jul 4 2010, 01:24 PM

Yes, it's just a new php interface to Mysql; I only skimmed, but it's a class, so gives you the advantages of OOP (object-oriented programming). But it isn't going to make any real difference to the mysql queries, and it's not likely that the conventional functions will simply disappear. If they did, there would be so many people who have large applications using those functions that someone would obviously write wrapper functions to get them back through the class interface.

And the functions all correspond anyway, so it really isn't a question of "learning" new function. (Surely you don't memorise these function details anyway? You just copy the last one, and check tricky bits in the manual.)

Posted by: Christian J Jul 4 2010, 05:28 PM

QUOTE(Brian Chandler @ Jul 4 2010, 08:24 PM) *

it's not likely that the conventional functions will simply disappear.

As long as the new ones don't lack some feature of the old ones. I don't think you can mix MySQL and MySQLi functions with the same MySQLi connection (or can you?).

Can you use the old functions at all when MySQLi is enabled in php.ini? I guess I should test that myself, but in the meantime http://www.php.net/manual/en/mysqli.installation.php says

"With versions of PHP 5.3 and newer, you can alternatively use the new MySQL Native Driver with mysqli. This gives a number of benefits over using libmysql."

whatever that means (FWIW I don't have PHP5.3).

QUOTE
(Surely you don't memorise these function details anyway?

Some of it will always stick, so I'll probably minimize confusion by being consistent.

Posted by: Brian Chandler Jul 5 2010, 04:56 AM

QUOTE(Christian J @ Jul 5 2010, 07:28 AM) *

QUOTE(Brian Chandler @ Jul 4 2010, 08:24 PM) *

it's not likely that the conventional functions will simply disappear.

As long as the new ones don't lack some feature of the old ones. I don't think you can mix MySQL and MySQLi functions with the same MySQLi connection (or can you?).


Why not? The database connection gives you a handle: both sets of functions use the handle to send requests to the database server. As long as they make sense the database server will respond appropriately.

It doesn't make sense to set out writing a bit of program with a jumble of different families of functions, but equally why should one function stop working (*how* *could* it stop working??) just because you are also calling other functions.

Remember that there is masses of code out there using the traditional php-mysql library. Programmers don't want this to "stop working" just because something else has been added. (Perhaps you have too much experience of the morass that is html-css, where having things stop working seems quite normal.)

QUOTE


Can you use the old functions at all when MySQLi is enabled in php.ini?



If the mysql library is installed, the functions will work. It is *inconceivable* (1) that they could mysteriously stop working because something else somewhere else has also been installed.

(1) Well, there are bugs, and things do not always work as advertised.

If you are new to this and learning, I would recommend using the traditional library, because you will find it much easier to get help with. If you are not currently learning to use classes and the rest of OOP, I *strongly* recommend using the traditional version. If you want to learn OOP later, going back to the mysql stuff and shifting it from procedural to OOP might be a good place to start.

HTH


Posted by: Ephraim F. Moya Jul 7 2010, 12:09 PM

I have learned over the years that improvements to php are really improvements.

I started using classes, including mysqli when I went to v5. It's better and I haven't found any downside. Use the newest stuff.

If you're NOT using classes -- start!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)