Andy-H Posted January 6, 2012 Share Posted January 6, 2012 Jordan Guest Re: MySQL vs MySQLi MySQLi is faster thus the name MySQL Improved. MySQLi also supports all of the features of MySQL 5.0 such as transactions. The MySQL (not improved) extension will also be dropped from PHP6 (you can still install it, if needed) and replaced with MySQLi. Just read that on another forum, is it true? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 I hope so. There's really zero reason you should be using it anymore. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted January 6, 2012 Author Share Posted January 6, 2012 Familiarity? lol Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 6, 2012 Share Posted January 6, 2012 It really isn't that big of a jump to switch. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 PHP6 won't be out for quite a while. Now is a good a time as any to learn MySQLi. It's not even a big difference at all if you don't take advantage of any of the new features. In most cases just stick an i at the end of the function and you're good to go. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted January 6, 2012 Author Share Posted January 6, 2012 I know, how much faster is MySQLi compared to PHP? Is it microseconds? I saw a benchmark where someone saved 2 seconds when requesting 30,000 rows, but it seems so awkward to me. I am writing an API at the moment, and have a database factory class, should I exclude support for mysql? Also, should I simply use the SPL MySQLi or write a wrapper for it? The reason I ask is because if I switch my query language, I would like to be able to change a single environment variable and have all my database class wrappers implementing a single interface, would it be do-able to replicate MySQLi's methods as a wrapper for postrgreSQL and other query languages? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted January 6, 2012 Author Share Posted January 6, 2012 Just been looking at MySQLi on php.net, is it possible to extend the class to add a connect and select_database method? I wan't my database factory to keep only one instance of MySQLi in existence, however, the only way I can see to connect is via the __construct method? I would like the ability to connect to one database, select a host, user, pass depending on userID, the connect the same MySQLi object using the database info returned, is it possible? Am I being stupid with the above and should just use SQL cluster and this wouldn't be required? I don't know how SQL clusters work - don't the still have to write to all servers meaning that all request's will go through 1 server anyway? Quote Link to comment Share on other sites More sharing options...
ignace Posted January 6, 2012 Share Posted January 6, 2012 Here's an example: interface DB { public function __construct(array $config); public function query($sql); } interface DB_Result { public function fetchAll(); } class DB_MySQLFunctions implements DB { private $conn; public function __construct(array $config) { $this->conn = mysql_connect($config['host'], $confg['user'], ..); } public function query($sql) { return new DB_MySQLFunctions_Result(mysql_query($sql, $this->conn)); } } class DB_PDO implements DB { private $pdo; public function __construct(array $config) { $this->pdo = new PDO($this->_PDODSN($config)); } public function query($sql) { $result = $this->pdo->query($sql); return new DB_PDO_Result($result); } private function _PDODSN($config) { /*..*/ } } class DB_PDO_Result implements DB_Result { private $result; public function __construct($result) { $this->result = $result; } public function fetchAll() { return $this->result->fetchAll(); } } And in your application you could have code like: /** * @param DB $db * @return DB_Result */ public function queryForAllUsers(DB $db) { return $db->query('SELECT * FROM users')->fetchAll(); } This code now works for all implementations of DB. So: $this->queryForAllUsers(new DB_MySQLFunctions); // using mysql_* $this->queryForAllUsers(new DB_PDO); // using PDO Quote Link to comment Share on other sites More sharing options...
requinix Posted January 6, 2012 Share Posted January 6, 2012 PHP 6 was scrapped. There are no plans for it whatsoever. Anything said about it is meaningless. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted January 6, 2012 Author Share Posted January 6, 2012 @ignace thanks, never seen it done like that before but seem's like it's pretty sturdy. @requinix ok, thanks, so theyre jumping straight to 7? I saw that they had problems with UTF-16 but didn't know they scrapped it completely. Quote Link to comment Share on other sites More sharing options...
premiso Posted January 6, 2012 Share Posted January 6, 2012 @requinix ok, thanks, so theyre jumping straight to 7? I saw that they had problems with UTF-16 but didn't know they scrapped it completely. I don't think so. I think it has just been scrapped till the devs can actually agree on stuff. So for now it is just going to be 5.x versions, and I doubt they will drop MySQL support in 5.x, too many apps depend on it. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 how much faster is MySQLi compared to PHP? With a direct comparison to MySQL it's really not any faster. But it still has a lot more useful features. Also, should I simply use the SPL MySQLi or write a wrapper for it? If you really want support for a lot of vendors then I would go with PDO. Either way, I definitely recommend a wrapper. The syntax is just ugly and cumbersome in my opinion. I don't want to type 10 lines of code every time I want a simple INSERT. Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2012 Share Posted January 7, 2012 PHP 6 was scrapped. There are no plans for it whatsoever. Anything said about it is meaningless. It's funny actually, because there were a few book publishers quick to jump on the php6 bandwagon to make some extra cash. That's right, there are actually books around on php6 (which no longer exists). Quote Link to comment 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.