shane18 Posted December 15, 2009 Share Posted December 15, 2009 MySQL MySQLi(Object Oriented) MySQLi(Procedural) I know how to use all three ways, but which way is the best? Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/ Share on other sites More sharing options...
corbin Posted December 15, 2009 Share Posted December 15, 2009 Typically MySQLi is seen as better. Slightly better performance, better API, so on. As for OOP or procedural, I personally prefer OOP, but it depends a lot on the style of what ever application you're using MySQLi in. Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-977505 Share on other sites More sharing options...
shane18 Posted December 15, 2009 Author Share Posted December 15, 2009 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 More sharing options...
shane18 Posted December 15, 2009 Author Share Posted December 15, 2009 To clear up my last post, is there anyway to make this code into one line? $USER = $DB->query("SELECT * FROM members WHERE id='$USER_ID'"); $USER = $USER->fetch_object(); Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-977515 Share on other sites More sharing options...
trq Posted December 15, 2009 Share Posted December 15, 2009 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 More sharing options...
Mchl Posted December 15, 2009 Share Posted December 15, 2009 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 More sharing options...
shane18 Posted December 15, 2009 Author Share Posted December 15, 2009 can u show me how to properly fetch 1 row from the db, and how to properly fetch multiple rows? my way is crappy and lazy. Thanks for ur opinions they really helped. Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-977749 Share on other sites More sharing options...
shane18 Posted December 15, 2009 Author Share Posted December 15, 2009 BUMP Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-978052 Share on other sites More sharing options...
Mchl Posted December 15, 2009 Share Posted December 15, 2009 Ther are pretty good examples in manual, for example here: mysqli_query or here: mysqli-result.fetch-assoc For some short introduction to error handling, see here: http://www.phpfreaks.com/blog/or-die-must-die Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-978118 Share on other sites More sharing options...
shane18 Posted December 15, 2009 Author Share Posted December 15, 2009 thanks Link to comment https://forums.phpfreaks.com/topic/185177-mysql-or-mysqli/#findComment-978119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.