-1

I am upgrading older code from mysql_ to mysqli and i found myself writing a replacement for the common :

mysql_result();

What i wrote was :

function mysqli_result($res, $row, $field=0) { 
$res->data_seek($row); 
$datarow = $res->fetch_array(); 
return $datarow[$field]; 
} 

But im curious, is there anyway to precisely benchmark the two without hindering any performance speed and if so what would be the best way about it ?

Pogrindis
  • 7,755
  • 5
  • 31
  • 44

2 Answers2

2

The mysql_* functions will be deprecated in PHP 5.5. It is not recommended for writing new code as it will be removed in the future.

With that said, concerns of benchmarks and performance are irrelevant. Furthermore, following the 80/20 rule, optimization should be focused on your queries and DB structure well before code.

Nonetheless, I did run my own simple benchmarks years ago when making the switch. I found mysqli to be more performant than mysql. Moreso when using prepared statements.

As noted by Your Common Sense, performance is also heavily dependent on how you write your code. Be sure you understand the difference in the libraries and which methods to use.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
1

MySQLi is an 'Improved' way of interfacing with the same database, it has many memory and speed enhancements in addition to support for;

  • Prepared Statemments
  • Multiple Statements
  • Transactions

MySQLi can also be written in both OOP style and procedural style.

If you scroll down to the bottom of the page on MySQLi Overview offers it will you'll see a comparison table.

If you're interested in benchmarks, I came across a blog which you might want to take a look at Blog - ioMeWeekly

  • Like many other "blog posts" this one can actually tell you nothing neither on the "speed difference" nor on the necessity of such a benchmark. – Your Common Sense Jul 15 '13 at 15:24
  • old mysql ext is okay with Prepared Statemments, Multiple Statements and Transactions. I can't believe so many people are dragging this rumor along – Your Common Sense Jul 15 '13 at 15:26
  • It provides the scripts enabling the reader to test themselves. It then answers the question 'Is it faster for me, in my environment?'. –  Jul 15 '13 at 15:27
  • Sadly, you don't get the point. This test is essentially useless by intention and wrong by implementation. In any environment. – Your Common Sense Jul 15 '13 at 15:32
  • Using PDO extension it supports prepared statements etc however the standard MySQL extension does not. Referencing: http://www.php.net/manual/en/mysqlinfo.api.choosing.php –  Jul 15 '13 at 15:34
  • PDO can emulate prepared statements. Mysql ext can do it as well. Referencing: own experience. – Your Common Sense Jul 15 '13 at 15:57