Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/254496-will-mysql-be-depreciated-in-php-6/
Share on other sites

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.

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?

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?

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

@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.

@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.

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.

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.