2. Who Am I?
• Nathaniel McHugh
• Ibuildings Sheffield
• Zend Certified PHP Developer
• Oracle certified MySQL Developer
• Like writing extensions like databases
• Never do anything useful
3. What is mysqlnd?
• PHP Extension created by owners of MySQL for PHP to
query MySQL databases
• It is not an alternative to the three MySQL extensions
existing namely, mysql, mysqli and pdo_mysql
• Although it is a PHP extension it exports no new PHP
functions
5. Libmysql vs mysqlnd
• C Library • PHP Extension
• GPL License • PHP License
• Linked at compile time • Included in PHP source
• Many Failing tests • Fewer failing tests
• May perform better
around buffered queries
6. How do I get mysqlnd?
The libysql way
--with-mysql[=DIR] --with-mysqli[=DIR] --with-pdo-mysql[=DIR]
e.g. on ubuntu this will be /usr/bin looking for mysql_config
The mysqlnd way
--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-
mysql=mysqlnd --with-mysql-sock[=DIR]
7. How do I get mysqlnd?
The libysql way
--with-mysql[=DIR] --with-mysqli[=DIR] --with-pdo-mysql[=DIR]
e.g. on ubuntu this will be /usr/bin looking for mysql_config
The mysqlnd way
--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-
mysql=mysqlnd --with-mysql-sock[=DIR]
11. Real world(ish) use case
Amazon RDS does not give users the SUPER privilege
and so you cannot change the timezone globally
Answer: set the timezone for every connection
12. mysqlnd_uh to the rescue
<?php
class proxy extends MysqlndUhConnection {
public function connect($res, $host, $user, $passwd, $db, $port, $sock
et, $mysql_flags) {
$ret = parent::connect($res, $host, $user, $passwd, $db, $port, $soc
ket, $mysql_flags);
$query = "SET time_zone = 'Europe/Moscow'";
parent::query($res, $query);
return $ret;
}
}
mysqlnd_uh_set_connection_proxy(new proxy());
$mysqli = new mysqli("127.0.0.1", "root", "youllNeverGuess", "test");
$result = $mysqli->query("SELECT NOW()");
var_dump(mysqli_fetch_all($result));
like useless things and to a certain extent this is one of them\n
Appologies if you know this stuff already but I was quite supprised when my colleague didn&#x2019;t think it&#x2019;s people switch of when hear dbs\n
\n
\n
recompile\nimportant to tell mysqlnd where your mysql server socket is as your now the client\nonce you have done that \n
another advantage mysqlnd is plugin architecture\n7 modules\n
lifted example from php.net documentation about writing mysqnd plugin as PHP extension\nto use get the mysqlnd function table back it up replace the function table with a custom one \nwith your own function and in that calling the original method\nlot of boiler plate stuff to build a PHP extension\n
on Pickle\nunstable there is a release which is missing some of the stuff we&#x2019;re going to look at\n
mysqlnd_uh extension is to allow you to use PHP to quickly do similar things\ngoing back to this slide at the moment this is the state of mysqlnd_uh \n\n
demo\n
showing example of result proxy\nresult functions undocumented\ndemo\ncurrent trunk unstable ask me if you want to use it\n