Jump to content

MySQL or MySQLi


shane18

Recommended Posts

Well, I really like MySQLi(Object Oriented)... but i hate having to have this extra line....

 

$USER = $DB->query("SELECT * FROM members WHERE id='$USER_ID'");
$USER = $USER->fetch_object();

 

Can I make that one line just like....

 

$USER = mysql_fetch_object(mysql_query("SELECT * FROM members WHERE id='$USER_ID'"));

Link to comment
https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-977507
Share on other sites

Can I make that one line just like....

$USER = mysql_fetch_object(mysql_query("SELECT * FROM members WHERE id='$USER_ID'"));

 

That is terrible code. What if mysql_query() fails? You'll have a hard time tracking down your issue if you simply return false to mysql_fetch_object().

 

Terrible code.

Link to comment
https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-977568
Share on other sites

MySQLi whenever possible. First and foremost it gives you prepared statements: the ultimate way to protect yourself against SQL injections (although inability to fetch the results into an array is a bit of a bummer).

Also better support for transactions (mysqli_autocommit) and charsets (mysqli_set_charset). It even allows for asynchronous queries (since PHP5.3 and with mysqlnd driver).

 

 

 

That is terrible code. What if mysql_query() fails? You'll have a hard time tracking down your issue if you simply return false to mysql_fetch_object().

 

QFT

Each of these commands should be surrounded with error handling code.

 

 

Link to comment
https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-977591
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.