kjtocool Posted November 27, 2007 Share Posted November 27, 2007 How do you decide which functions to use, mysql_ or mysqli_ ? I see most people on these forums using mysql_ , though I personally tend to use mysqli_ . In general, I was wondering your thoughts on which to use, and when. Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/ Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 If you have access to mysqli_* use them. Its not called mysqlimproved for nothing. Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-400659 Share on other sites More sharing options...
dbo Posted November 28, 2007 Share Posted November 28, 2007 Yeah, supposedly mysqli is the new and improved way. Some hosts don't have this way available though. I suggest "wrappering" these inside of your own class so that if you need to change them you change them in a single file instead of 8,000 places in your code. Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-400721 Share on other sites More sharing options...
Stopofeger Posted November 28, 2007 Share Posted November 28, 2007 I would love to use it but unfortunately most of my clients don't have it or won't have it. And most database classes don't use it either. Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-401061 Share on other sites More sharing options...
trq Posted November 28, 2007 Share Posted November 28, 2007 And most database classes don't use it either There is a mysqli database class, that if available is much better to use than any coded in php. Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-401063 Share on other sites More sharing options...
alefort Posted November 28, 2007 Share Posted November 28, 2007 I'll echo everyone else's thoughts, if you are going to use prebuilt php functions, use mysqli_. If you want to go one step further, as mentioned by a previous poster, use an abstraction layer that would allow you to change the calls within say one class, instead of throughout all your code. Zend_Db in the Zend Framework works beautifully! Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-401180 Share on other sites More sharing options...
448191 Posted November 30, 2007 Share Posted November 30, 2007 MySQLi provides an interface to some of the more advanced features of MySQL 4.1+, like transactions and prepared statements. The old mysql functions don't. I don't know if their is much reason to use mysqli if you don't use these features, but it doesn't hurt. Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-402677 Share on other sites More sharing options...
Guest Posted December 5, 2007 Share Posted December 5, 2007 I read up on mysqli, and in general it's stated to perform slower before PHP 5.1--there are no tests for beyond that version. As soon as I get home, I can post up a source. Personally, with exception to receiving multiple results from transactions (like insert ids for multiple inserts or querysets for multiple selects), it isn't hard to use MySQL 4.1+'s features (which are the highlight of the mysqli extension) with mysql_ functions. If you want to begin a transaction, you simply query mysql with the transaction BEGIN statement mysql_query('BEGIN', $dbh); and respectively, use the ROLLBACK or COMMIT statements after finishing up. But if you truly require the features of mysqli (multiple results), then go for it. It's there for those who need it! Quote Link to comment https://forums.phpfreaks.com/topic/79153-mysql_-or-mysqli-functions-which-to-use/#findComment-407094 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.