Login   Register  
PHP Classes
elePHPant
Icontem

What are the diferences?

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP Classes blog  >  The Plot to Kill PHP ...  >  All threads  >  What are the diferences?  >  (Un) Subscribe thread alerts  
Subject:What are the diferences?
Summary:Has anyone looked into the diferences between the diferent MySQL
Messages:7
Author:Fernando André
Date:2011-07-15 10:15:34
Update:2011-07-16 09:20:50
 

  1. What are the diferences?   Reply  
Picture of Fernando André
Fernando André
2011-07-15 10:19:13
Has anyone looked into the diferences between the diferent MySQL extensions?

The mysqli and PDO are more object oriented and mysqli is object oriented but closed around mysql logic...

I haven't wasted mutch time looking into them, in mysql extension basic of php I have used mysql_real_escape_string to parse input that whent into the sql query. I have this logic inside a class witch I think will ease the port to a diferent extension.

But the main question is, do we get speed, memory gain? What are the advantages of this new extensions?

Best regards,
FR

  2. Re: What are the diferences?   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-07-15 10:22:13 - In reply to message 1 from Fernando André
The only MySQL extension did not seem to be updated to support features available in newer MySQL server versions.

Anyway, if people should switch to a better MySQL extension, they should ignore mysqli and PDO and go right to MySQLND, which is a native PHP optimized driver developed by MySQL people having specifically PHP in mind.

  3. Re: What are the diferences?   Reply  
Picture of Artur Graniszewski
Artur Graniszewski
2011-07-15 15:40:15 - In reply to message 2 from Manuel Lemos
What? Tell me if I'm wrong, but MySQLnd is not a standalone library as MySQLi or MySQL or PDO. It's a internal db driver used by different MySQL* layers (like PDO, etc). You can link it from your own extensions.

http://dev.mysql.com/downloads/connector/php-mysqlnd/

What's more. In hosting company I worked for it is enabled by default (because of the performance reasons), and none of the existing PHP scripts of the company's customers has been broken (yet they use old MySQL extensions/PDO/mysqli)

  4. Re: What are the diferences?   Reply  
Picture of Mustafa Rampurawala
Mustafa Rampurawala
2011-07-15 15:46:49 - In reply to message 1 from Fernando André
Hi Fernando,
I too have got a bird eye look on the mysqli extention. But, i think its nice to adopt it in the future code development, and try updating the old code on the way. Here i wiould like to bring 2 things into notice.

First, for those who just want to upgrade from mysql to mysqli to make their script compatible, nearly all the mysql methods are supported by mysqli. The difference is very small like, mysql_connect is now mysqli_connect (here, 1 can now pass the database name too in the same connect statement, or if preferred can do it the same old way with mysqli_select_db) and mysql_query becomes mysqli_query, except for the fact that the $link comes before $query and now $link is not optional.

Second, for those who want to reap the benefits of the mysqli extention, there are many good things to write, but that can be done in its own post. here will only like to highlight that you no longer need mysql_real_escape_string now, just prepare the statement and then pass values with there type and mysqli will take care of the rest. Also, as you asked, the speed difference and resource handling efficiency improvement can be seen here, as the database overhead is greatly reduced in prepared statements, especially if you need to insert/update many records in single batch. Not tested, but officially its said to be 40 times faster.

Mustafa Rampurawla

  5. Re: What are the diferences?   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-07-16 04:30:04 - In reply to message 3 from Artur Graniszewski
Sorry, I expressed myself in a misleading way.

What I thought but did not say, is that there should be a new PHP MySQL API to access MySQL database asynchronously, ala Node.js. That could be used to make PHP run faster by doing some work while queries are executed in parallel.

http://www.phpclasses.org/blog/post/133-Accelerate-scripts-r ...

http://www.phpclasses.org/discuss/blog/PHP-Classes-blog/post ...

  6. Re: What are the diferences?   Reply  
Picture of Fernando André
Fernando André
2011-07-16 09:07:42 - In reply to message 5 from Manuel Lemos
About paralel work in MySQL while PHP can go along and do something else...
What about pcntl_fork()
Take a look at this link:
http://php.net/manual/en/function.pcntl-fork.php#99350

Althought a fork happens the resource connection is allways the same. And this looks to be like a limitation of the Zend Engine.


  7. Re: What are the diferences?   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-07-16 09:20:50 - In reply to message 6 from Fernando André
We all know the pcntl extension but that is not what we are talking about when referring to asynchronous programming.

Asynchronous programming is for instance executing a query and instead of waiting a few seconds for the query to finish returning the results, your PHP can do something else in parallel and be notified when the query is done, for instance invoking a callback a la JavaScript.

That would make a more efficient use of CPU and I/O resources. In Node.js, you can do server-side asynchronous programming as a natural thing.

In PHP, there is some support to access the network and files asynchronously, but nothing for accessing databases asynchronously, although Jamie commented it is possible to perform some tricks using mysqlnd that he ended up not revealing, probably because it would require disclosing some business secrets of his company.

Until PHP has specific support of asynchronous programming, Node.js and similar JavaScript solutions will be more recommended for certain high concurrency applications, like chat servers or COMET based applications.

You may want to check the Lately in JavaScript podcast to learn more about this:

http://www.jsclasses.org/blog/post/3-Is-NodeJS-going-to-be-t ...

Or check a few Node.js based objects in the JSClasses site:

http://www.jsclasses.org/browse/class/12.html