SlideShare une entreprise Scribd logo
1  sur  49
2014/10/11 
PHP Conference Japan 2014 
do_aki 
1 
updated 2014-10-21
@do_aki 
@do_aki 
http://do-aki.net/ 
2
agenda 
1. about mysqlnd 
– position, role 
2. libmysql vs mysqlnd 
– functions, features 
3. mysqlnd internals 
I. Type of returning values 
II.Memory usage 
3
1.about mysqlnd 
4
MySQL client libraries in PHP 
mysql_connect 
mysqli 
PDO 
Doctrine 
Eloquent 
ZendDB 
Aura.Sql 
ADOdb 
PEAR_MDB2 
PEAR_DB 
5
Those libraries use 
mysql/mysqli/pdo extensions 
6 
MySQL 
client 
libraries 
in PHP 
is 
/ 
use 
mysql 
extension 
mysqli 
extension 
pdo 
extension 
(mysql driver)
mysql / mysqli / 
pdo (mysql_driver) 
access MySQL server 
directly? 
7
No 
8
Communication between 
MySQL server and PHP 
• Network access (tcp, socket) 
• Encryption (SSL) or not 
• Analyze Wire Protocol 
• Compression (deflate) or not 
• Convert to (or from) PHP variables 
• Error Handring (Exception) 
9
Communication between 
MySQL server and PHP 
• Network access (tcp, socket) 
• Encryption (SSL) or not 
• Analyze Wire Protocol 
• Compression (deflate) or not 
• Convert to (or from) PHP variables 
• Error Handring (Exception) 
mysql/mysqli/pdo 
mysqlnd 
/ 
libmysql 
10
Application 
ADOdb Zend_DB Doctrine 
Chart of 
mysqli 
PEAR::MDB2 
mysql PDO 
mysqlnd 
libmysql 
Zend 
Engine 
PHP 
Script 
MySQL Server 
ref:http://d.hatena. 
ne.jp/do_aki/2011121 
4/1323831558 
11
2.libmysql vs mysqlnd 
12
Application 
ADOdb Zend_DB Doctrine 
Chart of 
mysqli 
PEAR::MDB2 
mysql PDO 
mysqlnd 
libmysql 
Zend 
Engine 
PHP 
Script 
MySQL Server 
ref:http://d.hatena. 
ne.jp/do_aki/2011121 
4/1323831558 
13
libmysql vs mysqlnd 
• libmysqlclient (Connector/C) 
– C library 
– Oracle (MySQL AB) 
– matured 
• mysqlnd 
– PHP extension 
– PHP Community (Andrey, Johannes, Ulf) 
– relatively recent 
14
compile options (example) 
• libmysql 
./configure  
--with-mysql=/usr  
--with-mysqli=/usr/bin/mysql_config  
--with-pdo-mysql=/usr 
• mysqlnd 
./configure  
--with-mysql=mysqlnd  
--with-mysqli=mysqlnd  
--with-pdo-mysql=mysqlnd 
15
mysqlnd and php versions 
• not available 
(only libmysql) 
before 
php 5.3 
• bundled but optional 
(default is libmysql) 
php 5.3 
series 
• default 
(libmysql is optional) 
php 5.4 
or later 
16 
*libmysql is not deprecated
which is used? 
• php –i or phpinfo() 
– mysql : Client API version 
– mysqli : Client API library version 
– pdo_mysql : Client API version 
mysqli : mysqli_get_client_info() 
PDO : $pdo->getAttribute( 
PDO::ATTR_CLIENT_VERSION) 
• include “mysqlnd” string or not 
17 
same as
pros 
• resolve license problems 
– libmysql: GPLv2 
with FOSS License Exception 
– mysqlnd : PHP license 
• not need build libmysqlclient before 
compile PHP 
– mysqlnd is bundled in php source code 
• “highly optimized for and tightly 
integrated into PHP” 
18
cons 
• not yet matured 
– libmysqlclient is widely used. 
at any os, as any language bindings… 
– mysqlnd is limited used. 
compared with libmysql 
19
incompatibilities 
• mysqlnd cannot use OLD_PASSWORD 
– not support MySQL server before 4.1 
– "mysqlnd cannot connect to MySQL 4.1+ using 
old authentication" 
• mysqlnd don’t read “my.cnf” 
– affect charset 
– no PDO::MYSQL_ATTR_READ_DEFAULT_FILE 
• Type of returning value is different 
– example: BIT type written by manual 
– It mentions later 
20
mysqlnd only 
• Asynchronous, non-blocking queries 
– MYSQLI_ASYNC (mysqli::query) 
– mysqli::reap_async_query 
– mysqli::poll 
• performance statistics 
– mysqli_get_client_stats 
– mysqli::get_connection_stats 
– http://php.net/manual/mysqlnd.stats.php 
• functions 
– mysqli_stmt::get_result 
– mysqli_result::fetch_all 
21
plugins 
• mysqlnd_ms 
– Replication and load balancing 
– http://pecl.php.net/package/mysqlnd_ms 
• mysqlnd_qc 
– Client side query cache 
– http://pecl.php.net/package/mysqlnd_qc 
• mysqlnd_uh 
– MySQLnd Userland Handler 
– http://pecl.php.net/package/mysqlnd_uh 
• mysqlnd_memcache 
– Translating SQL for InnoDB Memcached 
– http://pecl.php.net/package/mysqlnd_memcache 
22
plugins (removed?) 
• mysqlnd_mux 
– Simuler mysqlnd_ms? 
• mysqlnd_pscache 
– Prepared statement cache 
• mysqlnd_sip 
– SQL Injection Protection 
• mysqlnd_mc 
– Multi Connect 
23
3.mysqlnd internals 
24
Server side prepared statement 
type of prepared statement 
prepare SELECT age FROM user COM_PREPARE 
WHERE name = ? 
execute bind parameter "do_aki" COM_EXECUTE 
[Preventing SQL Injection] 
Client side prepared statement 
prepare 
SELECT age FROM user 
WHERE name = ? 
execute SELECT age FROM user COM_QUERY 
WHERE name = ‘do_aki’ 
25 
[default PDO settings]
Server side prepared statement 
prepared statement and protocols 
prepare SELECT age FROM user COM_PREPARE 
WHERE name = ? 
execute bind parameter "do_aki" COM_EXECUTE 
result set 29 (integer) 
binary protocol 
Client side prepared statement 
prepare 
SELECT age FROM user 
WHERE name = ? 
execute SELECT age FROM user COM_QUERY 
WHERE name = ‘do_aki’ 
result set “29” (string) 
text protocol 
26
I.Type of returning values 
27
example 
mysql> CREATE TABLE bits( 
id int, 
b bit(8), 
f float 
); 
mysql> insert into bits values 
(1, b'1010', 1.1); 
28
PDO 
text protocol 
$pdo->setAttribute( 
PDO::ATTR_EMULATE_PREPARES, true); 
$stmt = $pdo->prepare("SELECT * FROM bits"); 
$stmt->execute(); 
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC); 
binary protocol 
$pdo->setAttribute( 
PDO::ATTR_EMULATE_PREPARES, false); 
$stmt = $pdo->prepare("SELECT * FROM bits"); 
$stmt->execute(); 
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 
29
PDO (libmysql) 
text protocol 
array(1) { 
[0]=> 
array(3) { 
[“id”]=> 
string(1) "1" 
[“b”]=> 
string(1) " 
" 
[“f”]=> 
string(3) "1.1" 
} 
} 
binary protocol 
array(1) { 
[0]=> 
array(3) { 
[“id”]=> 
string(1) "1" 
[“b”]=> 
string(1) " 
" 
[“f”]=> 
string(3) "1.1" 
} 
} 
“b” value is 0x10 30
PDO (mysqlnd) 
text protocol 
array(1) { 
[0]=> 
array(3) { 
[“id”]=> 
string(1) "1" 
[“b”]=> 
string(2) "10" 
[“f”]=> 
string(3) "1.1" 
} 
} 
binary protocol 
array(1) { 
[0]=> 
array(3) { 
[“id”]=> 
int(1) 
[“b”]=> 
int(10) 
[“f”]=> 
float(1.1000000238419) 
} 
} 
31
PDO 
text protocol 
array(3) { 
[“id”]=> 
string(1) "1" 
[“b”]=> 
string(1) “x10" 
[“f”]=> 
string(3) "1.1" 
} 
binary protocol 
array(3) { 
[“id”]=> 
string(1) "1" 
[“b”]=> 
string(1) “x10" 
[“f”]=> 
string(3) "1.1" 
} 
mysql 
nd 
array(3) { 
[“id”]=> 
string(1) "1" 
[“b”]=> 
string(2) "10" 
[“f”]=> 
string(3) "1.1" 
} 
array(3) { 
[“id”]=> 
int(1) 
[“b”]=> 
int(10) 
[“f”]=> 
float(1.1000000238419) 
} 
libmy 
sql 
32
mysqli 
text protocol 
$res = $mysqli->query("SELECT * FROM bits"); 
while($row = $res->fetch_assoc()) { 
$rows[] = $row; 
} 
var_dump($rows); 
binary protocol 
$stmt = $mysqli->prepare("SELECT * FROM bits"); 
$stmt->execute(); 
$stmt->bind_result($id, $b, $f); 
while($stmt->fetch()) { 
$rows[] = [‘id’=>$id, ‘b’=>$b, ‘f’=>$f]; 
} 
var_dump($rows); 
33
mysqli (libmysql/mysqlnd) 
text protocol 
array(1) { 
[0]=> 
array(3) { 
[0]=> 
string(1) "1" 
[1]=> 
string(2) "10" 
[2]=> 
string(3) "1.1" 
} 
} 
binary protocol 
array(1) { 
[0]=> 
array(3) { 
[0]=> 
int(1) 
[1]=> 
int(10) 
[2]=> 
float(1.1000000238419) 
} 
} 
34
II.Memory usage 
35
fetch (libmysql) 
$id $name $dt 
123 “do_aki” “2014-10-11 11:30:00” 
MySQL Server 
mysqli/pdo 
libmysql 
“id”:123, “name”:”do_aki”, 
“datetime”: “2014-10-11 11:30:00” 
36
fetch (mysqlnd) 
$id $name $dt 
mysqli/pdo 
3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” 
MySQL Server 
mysqlnd 
37
fetch (detail) 
zval* zval* zval* 
$id $name $dt 
zval zval zval MYSQLND_RES 
3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” 
MySQL Server 
MEMORY POOL (use malloc) 
38 
line 1 
internal buffers
fetch * N 
zval* zval* zval* 
$id $name $dt 
zval zval zval MYSQLND_RES 
3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” 
MySQL Server 
MEMORY POOL (use malloc) 
39 
line N 
internal buffers 
geting fat 
until statement 
released
solution for reduced memory 
• use MYSQLI_STORE_RESULT_COPY_DATA 
– fetch with copy 
– php >= 5.6.0 
– Not for PDO yet… 
– http://blog.ulf-wendel.de/2014/php-5- 
7-mysqlnd-memory-optimizations/ 
40
fetch with copy 
zval zval zval 
no internal buffers 
3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” 
MySQL Server 
MYSQLND_RES 
$id $name $dt 
41 
line N 
123 “do_aki” “2014-10-11 11:30:00”
but but but 
42
fetch (text protocol) 
$id $name $dt 
mysqli/pdo 
3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” 
MySQL Server 
mysqlnd 
43
fetch (binary protocol) 
$id $name $dt 
MySQL Server 
mysqlnd 
123 6 "do_aki” 2014-10-11 
11:30:00 
mysqli/pdo 
123 “do_aki” “2014-10-11 11:30:00” 
44
fetch (detail) 
zval* zval* zval* 
$id $name $dt 
zval zval zval MYSQLND_RES 
123 “do_aki” “2014-10-11 11:30:00” 
123 6 "do_aki” 2014-10-11 
11:30:00 
MySQL Server 
45 
line 1
fetch*N 
zval* zval* zval* 
$id $name $dt 
zval zval zval MYSQLND_RES 
111222333 “““dddooo___aaakkkiii””” ““2“2020101414-4-1-1010-0-1-1111 1 1 1111:1:3:3030:0:0:0000”0”” 
123 “do_aki” “2014-10-11 11:30:00” 
123 6 "do_aki” 2014-10-11 
11:30:00 
MySQL Server 
46 
line N
fetch*N 
zval* zval* zval* 
$id $name $dt 
zval zval zval MYSQLND_RES 
111222333 “““dddooo___aaakkkiii””” ““2“2020101414-4-1-1010-0-1-1111 1 1 1111:1:3:3030:0:0:0000”0”” 
123 “do_aki” “2014-10-11 11:30:00” 
123 6 "do_aki” 2014-10-11 
11:30:00 
MySQL Server 
47 
increases 
memory usage 
each fetch 
(until statement 
released) 
cannot use 
“MYSQLI_STORE_RE 
SULT_COPY_DATA” 
to prepared 
statement
Conclusion 
• I explain mysqlnd 
• mysqlnd and libmysql work 
differently 
• use mysqli if you want to full 
functions of mysqlnd 
• Prepared statement…… 
48
Thank you 
2014/10/11 
PHP Conference Japan 2014 
do_aki 
49

Contenu connexe

Tendances

WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeSveta Smirnova
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in PracticeNoah Davis
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rbKen Collins
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Undelete (and more) rows from the binary log
Undelete (and more) rows from the binary logUndelete (and more) rows from the binary log
Undelete (and more) rows from the binary logFrederic Descamps
 
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram VaswaniHigh Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswanivvaswani
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objectswebhostingguy
 
What's New in the PHP Driver
What's New in the PHP DriverWhat's New in the PHP Driver
What's New in the PHP DriverMongoDB
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeWim Godden
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploySimon Su
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappersPositive Hack Days
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 

Tendances (19)

WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rb
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Undelete (and more) rows from the binary log
Undelete (and more) rows from the binary logUndelete (and more) rows from the binary log
Undelete (and more) rows from the binary log
 
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram VaswaniHigh Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
 
What's New in the PHP Driver
What's New in the PHP DriverWhat's New in the PHP Driver
What's New in the PHP Driver
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
My sql administration
My sql administrationMy sql administration
My sql administration
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
 
Malcon2017
Malcon2017Malcon2017
Malcon2017
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
ROracle
ROracle ROracle
ROracle
 

En vedette

『例えば、PHPを避ける』以降PHPはどれだけ安全になったか
『例えば、PHPを避ける』以降PHPはどれだけ安全になったか『例えば、PHPを避ける』以降PHPはどれだけ安全になったか
『例えば、PHPを避ける』以降PHPはどれだけ安全になったかHiroshi Tokumaru
 
N対1 レプリケーション + Optimizer Hint
N対1 レプリケーション + Optimizer HintN対1 レプリケーション + Optimizer Hint
N対1 レプリケーション + Optimizer Hintdo_aki
 
WP-CLI (WordBench Sendai 20140628)
WP-CLI (WordBench Sendai 20140628)WP-CLI (WordBench Sendai 20140628)
WP-CLI (WordBench Sendai 20140628)Kazue Igarashi
 
PHP AST 徹底解説(補遺)
PHP AST 徹底解説(補遺)PHP AST 徹底解説(補遺)
PHP AST 徹底解説(補遺)do_aki
 
Writing php extensions in golang
Writing php extensions in golangWriting php extensions in golang
Writing php extensions in golangdo_aki
 
php7's ast
php7's astphp7's ast
php7's astdo_aki
 
signal の話 或いは Zend Signals とは何か
signal の話 或いは Zend Signals とは何かsignal の話 或いは Zend Signals とは何か
signal の話 或いは Zend Signals とは何かdo_aki
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingSteve Rhoades
 
PHP classの教室
PHP classの教室PHP classの教室
PHP classの教室Yusuke Ando
 
Advanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/Min
Advanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/MinAdvanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/Min
Advanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/MinMasahiro Nagano
 
今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンス今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンスHidenori Ishii
 
PHP AST 徹底解説
PHP AST 徹底解説PHP AST 徹底解説
PHP AST 徹底解説do_aki
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティスAmazon Web Services Japan
 

En vedette (14)

『例えば、PHPを避ける』以降PHPはどれだけ安全になったか
『例えば、PHPを避ける』以降PHPはどれだけ安全になったか『例えば、PHPを避ける』以降PHPはどれだけ安全になったか
『例えば、PHPを避ける』以降PHPはどれだけ安全になったか
 
N対1 レプリケーション + Optimizer Hint
N対1 レプリケーション + Optimizer HintN対1 レプリケーション + Optimizer Hint
N対1 レプリケーション + Optimizer Hint
 
WP-CLI (WordBench Sendai 20140628)
WP-CLI (WordBench Sendai 20140628)WP-CLI (WordBench Sendai 20140628)
WP-CLI (WordBench Sendai 20140628)
 
PHP AST 徹底解説(補遺)
PHP AST 徹底解説(補遺)PHP AST 徹底解説(補遺)
PHP AST 徹底解説(補遺)
 
Writing php extensions in golang
Writing php extensions in golangWriting php extensions in golang
Writing php extensions in golang
 
php7's ast
php7's astphp7's ast
php7's ast
 
signal の話 或いは Zend Signals とは何か
signal の話 或いは Zend Signals とは何かsignal の話 或いは Zend Signals とは何か
signal の話 或いは Zend Signals とは何か
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
PHP classの教室
PHP classの教室PHP classの教室
PHP classの教室
 
Advanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/Min
Advanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/MinAdvanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/Min
Advanced nginx in mercari - How to handle over 1,200,000 HTTPS Reqs/Min
 
今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンス今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンス
 
PHP AST 徹底解説
PHP AST 徹底解説PHP AST 徹底解説
PHP AST 徹底解説
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
 

Similaire à 20141011 mastering mysqlnd

Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013   MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013 Serge Frezefond
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Philip Zhong
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Chris Barber
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioningSource Ministry
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsUlf Wendel
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbaiaadi Surve
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuRedis Labs
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part IIFirdaus Adib
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesDave Stokes
 
Php and database functionality
Php and database functionalityPhp and database functionality
Php and database functionalitySayed Ahmed
 

Similaire à 20141011 mastering mysqlnd (20)

Mysqlnd uh
Mysqlnd uhMysqlnd uh
Mysqlnd uh
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013   MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
My Sq Ldb Tut
My Sq Ldb TutMy Sq Ldb Tut
My Sq Ldb Tut
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
Php and database functionality
Php and database functionalityPhp and database functionality
Php and database functionality
 

Plus de do_aki

Tritonn から Elasticsearch への移行話
Tritonn から Elasticsearch への移行話Tritonn から Elasticsearch への移行話
Tritonn から Elasticsearch への移行話do_aki
 
php-src の歩き方
php-src の歩き方php-src の歩き方
php-src の歩き方do_aki
 
PHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 とPHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 とdo_aki
 
PHPとシグナル、その裏側
PHPとシグナル、その裏側PHPとシグナル、その裏側
PHPとシグナル、その裏側do_aki
 
再考:列挙型
再考:列挙型再考:列挙型
再考:列挙型do_aki
 
20150212 プレゼンテーションzen
20150212 プレゼンテーションzen20150212 プレゼンテーションzen
20150212 プレゼンテーションzendo_aki
 
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」do_aki
 
20141017 introduce razor
20141017 introduce razor20141017 introduce razor
20141017 introduce razordo_aki
 
php in ruby
php in rubyphp in ruby
php in rubydo_aki
 
PHP から Groonga を使うにはこんなコードになるよ!
PHP から Groonga を使うにはこんなコードになるよ!PHP から Groonga を使うにはこんなコードになるよ!
PHP から Groonga を使うにはこんなコードになるよ!do_aki
 
N:1 Replication meets MHA
N:1 Replication meets MHAN:1 Replication meets MHA
N:1 Replication meets MHAdo_aki
 
Php radomize
Php radomizePhp radomize
Php radomizedo_aki
 
php and sapi and zendengine2 and...
php and sapi and zendengine2 and...php and sapi and zendengine2 and...
php and sapi and zendengine2 and...do_aki
 
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editorセキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editordo_aki
 
マスタN対スレーブ1レプリケーションの作り方 ~あれから~
マスタN対スレーブ1レプリケーションの作り方 ~あれから~マスタN対スレーブ1レプリケーションの作り方 ~あれから~
マスタN対スレーブ1レプリケーションの作り方 ~あれから~do_aki
 
Immortal
ImmortalImmortal
Immortaldo_aki
 
Excel is image viewer
Excel is image viewerExcel is image viewer
Excel is image viewerdo_aki
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby do_aki
 
Ruby and comparison_and...php
Ruby and comparison_and...phpRuby and comparison_and...php
Ruby and comparison_and...phpdo_aki
 
Sore php
Sore phpSore php
Sore phpdo_aki
 

Plus de do_aki (20)

Tritonn から Elasticsearch への移行話
Tritonn から Elasticsearch への移行話Tritonn から Elasticsearch への移行話
Tritonn から Elasticsearch への移行話
 
php-src の歩き方
php-src の歩き方php-src の歩き方
php-src の歩き方
 
PHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 とPHP と SAPI と ZendEngine3 と
PHP と SAPI と ZendEngine3 と
 
PHPとシグナル、その裏側
PHPとシグナル、その裏側PHPとシグナル、その裏側
PHPとシグナル、その裏側
 
再考:列挙型
再考:列挙型再考:列挙型
再考:列挙型
 
20150212 プレゼンテーションzen
20150212 プレゼンテーションzen20150212 プレゼンテーションzen
20150212 プレゼンテーションzen
 
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
 
20141017 introduce razor
20141017 introduce razor20141017 introduce razor
20141017 introduce razor
 
php in ruby
php in rubyphp in ruby
php in ruby
 
PHP から Groonga を使うにはこんなコードになるよ!
PHP から Groonga を使うにはこんなコードになるよ!PHP から Groonga を使うにはこんなコードになるよ!
PHP から Groonga を使うにはこんなコードになるよ!
 
N:1 Replication meets MHA
N:1 Replication meets MHAN:1 Replication meets MHA
N:1 Replication meets MHA
 
Php radomize
Php radomizePhp radomize
Php radomize
 
php and sapi and zendengine2 and...
php and sapi and zendengine2 and...php and sapi and zendengine2 and...
php and sapi and zendengine2 and...
 
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editorセキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
 
マスタN対スレーブ1レプリケーションの作り方 ~あれから~
マスタN対スレーブ1レプリケーションの作り方 ~あれから~マスタN対スレーブ1レプリケーションの作り方 ~あれから~
マスタN対スレーブ1レプリケーションの作り方 ~あれから~
 
Immortal
ImmortalImmortal
Immortal
 
Excel is image viewer
Excel is image viewerExcel is image viewer
Excel is image viewer
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby
 
Ruby and comparison_and...php
Ruby and comparison_and...phpRuby and comparison_and...php
Ruby and comparison_and...php
 
Sore php
Sore phpSore php
Sore php
 

Dernier

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

20141011 mastering mysqlnd

  • 1. 2014/10/11 PHP Conference Japan 2014 do_aki 1 updated 2014-10-21
  • 3. agenda 1. about mysqlnd – position, role 2. libmysql vs mysqlnd – functions, features 3. mysqlnd internals I. Type of returning values II.Memory usage 3
  • 5. MySQL client libraries in PHP mysql_connect mysqli PDO Doctrine Eloquent ZendDB Aura.Sql ADOdb PEAR_MDB2 PEAR_DB 5
  • 6. Those libraries use mysql/mysqli/pdo extensions 6 MySQL client libraries in PHP is / use mysql extension mysqli extension pdo extension (mysql driver)
  • 7. mysql / mysqli / pdo (mysql_driver) access MySQL server directly? 7
  • 9. Communication between MySQL server and PHP • Network access (tcp, socket) • Encryption (SSL) or not • Analyze Wire Protocol • Compression (deflate) or not • Convert to (or from) PHP variables • Error Handring (Exception) 9
  • 10. Communication between MySQL server and PHP • Network access (tcp, socket) • Encryption (SSL) or not • Analyze Wire Protocol • Compression (deflate) or not • Convert to (or from) PHP variables • Error Handring (Exception) mysql/mysqli/pdo mysqlnd / libmysql 10
  • 11. Application ADOdb Zend_DB Doctrine Chart of mysqli PEAR::MDB2 mysql PDO mysqlnd libmysql Zend Engine PHP Script MySQL Server ref:http://d.hatena. ne.jp/do_aki/2011121 4/1323831558 11
  • 13. Application ADOdb Zend_DB Doctrine Chart of mysqli PEAR::MDB2 mysql PDO mysqlnd libmysql Zend Engine PHP Script MySQL Server ref:http://d.hatena. ne.jp/do_aki/2011121 4/1323831558 13
  • 14. libmysql vs mysqlnd • libmysqlclient (Connector/C) – C library – Oracle (MySQL AB) – matured • mysqlnd – PHP extension – PHP Community (Andrey, Johannes, Ulf) – relatively recent 14
  • 15. compile options (example) • libmysql ./configure --with-mysql=/usr --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr • mysqlnd ./configure --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 15
  • 16. mysqlnd and php versions • not available (only libmysql) before php 5.3 • bundled but optional (default is libmysql) php 5.3 series • default (libmysql is optional) php 5.4 or later 16 *libmysql is not deprecated
  • 17. which is used? • php –i or phpinfo() – mysql : Client API version – mysqli : Client API library version – pdo_mysql : Client API version mysqli : mysqli_get_client_info() PDO : $pdo->getAttribute( PDO::ATTR_CLIENT_VERSION) • include “mysqlnd” string or not 17 same as
  • 18. pros • resolve license problems – libmysql: GPLv2 with FOSS License Exception – mysqlnd : PHP license • not need build libmysqlclient before compile PHP – mysqlnd is bundled in php source code • “highly optimized for and tightly integrated into PHP” 18
  • 19. cons • not yet matured – libmysqlclient is widely used. at any os, as any language bindings… – mysqlnd is limited used. compared with libmysql 19
  • 20. incompatibilities • mysqlnd cannot use OLD_PASSWORD – not support MySQL server before 4.1 – "mysqlnd cannot connect to MySQL 4.1+ using old authentication" • mysqlnd don’t read “my.cnf” – affect charset – no PDO::MYSQL_ATTR_READ_DEFAULT_FILE • Type of returning value is different – example: BIT type written by manual – It mentions later 20
  • 21. mysqlnd only • Asynchronous, non-blocking queries – MYSQLI_ASYNC (mysqli::query) – mysqli::reap_async_query – mysqli::poll • performance statistics – mysqli_get_client_stats – mysqli::get_connection_stats – http://php.net/manual/mysqlnd.stats.php • functions – mysqli_stmt::get_result – mysqli_result::fetch_all 21
  • 22. plugins • mysqlnd_ms – Replication and load balancing – http://pecl.php.net/package/mysqlnd_ms • mysqlnd_qc – Client side query cache – http://pecl.php.net/package/mysqlnd_qc • mysqlnd_uh – MySQLnd Userland Handler – http://pecl.php.net/package/mysqlnd_uh • mysqlnd_memcache – Translating SQL for InnoDB Memcached – http://pecl.php.net/package/mysqlnd_memcache 22
  • 23. plugins (removed?) • mysqlnd_mux – Simuler mysqlnd_ms? • mysqlnd_pscache – Prepared statement cache • mysqlnd_sip – SQL Injection Protection • mysqlnd_mc – Multi Connect 23
  • 25. Server side prepared statement type of prepared statement prepare SELECT age FROM user COM_PREPARE WHERE name = ? execute bind parameter "do_aki" COM_EXECUTE [Preventing SQL Injection] Client side prepared statement prepare SELECT age FROM user WHERE name = ? execute SELECT age FROM user COM_QUERY WHERE name = ‘do_aki’ 25 [default PDO settings]
  • 26. Server side prepared statement prepared statement and protocols prepare SELECT age FROM user COM_PREPARE WHERE name = ? execute bind parameter "do_aki" COM_EXECUTE result set 29 (integer) binary protocol Client side prepared statement prepare SELECT age FROM user WHERE name = ? execute SELECT age FROM user COM_QUERY WHERE name = ‘do_aki’ result set “29” (string) text protocol 26
  • 27. I.Type of returning values 27
  • 28. example mysql> CREATE TABLE bits( id int, b bit(8), f float ); mysql> insert into bits values (1, b'1010', 1.1); 28
  • 29. PDO text protocol $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, true); $stmt = $pdo->prepare("SELECT * FROM bits"); $stmt->execute(); var_dump($stmt->fetchAll(PDO::FETCH_ASSOC); binary protocol $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false); $stmt = $pdo->prepare("SELECT * FROM bits"); $stmt->execute(); var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 29
  • 30. PDO (libmysql) text protocol array(1) { [0]=> array(3) { [“id”]=> string(1) "1" [“b”]=> string(1) " " [“f”]=> string(3) "1.1" } } binary protocol array(1) { [0]=> array(3) { [“id”]=> string(1) "1" [“b”]=> string(1) " " [“f”]=> string(3) "1.1" } } “b” value is 0x10 30
  • 31. PDO (mysqlnd) text protocol array(1) { [0]=> array(3) { [“id”]=> string(1) "1" [“b”]=> string(2) "10" [“f”]=> string(3) "1.1" } } binary protocol array(1) { [0]=> array(3) { [“id”]=> int(1) [“b”]=> int(10) [“f”]=> float(1.1000000238419) } } 31
  • 32. PDO text protocol array(3) { [“id”]=> string(1) "1" [“b”]=> string(1) “x10" [“f”]=> string(3) "1.1" } binary protocol array(3) { [“id”]=> string(1) "1" [“b”]=> string(1) “x10" [“f”]=> string(3) "1.1" } mysql nd array(3) { [“id”]=> string(1) "1" [“b”]=> string(2) "10" [“f”]=> string(3) "1.1" } array(3) { [“id”]=> int(1) [“b”]=> int(10) [“f”]=> float(1.1000000238419) } libmy sql 32
  • 33. mysqli text protocol $res = $mysqli->query("SELECT * FROM bits"); while($row = $res->fetch_assoc()) { $rows[] = $row; } var_dump($rows); binary protocol $stmt = $mysqli->prepare("SELECT * FROM bits"); $stmt->execute(); $stmt->bind_result($id, $b, $f); while($stmt->fetch()) { $rows[] = [‘id’=>$id, ‘b’=>$b, ‘f’=>$f]; } var_dump($rows); 33
  • 34. mysqli (libmysql/mysqlnd) text protocol array(1) { [0]=> array(3) { [0]=> string(1) "1" [1]=> string(2) "10" [2]=> string(3) "1.1" } } binary protocol array(1) { [0]=> array(3) { [0]=> int(1) [1]=> int(10) [2]=> float(1.1000000238419) } } 34
  • 36. fetch (libmysql) $id $name $dt 123 “do_aki” “2014-10-11 11:30:00” MySQL Server mysqli/pdo libmysql “id”:123, “name”:”do_aki”, “datetime”: “2014-10-11 11:30:00” 36
  • 37. fetch (mysqlnd) $id $name $dt mysqli/pdo 3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” MySQL Server mysqlnd 37
  • 38. fetch (detail) zval* zval* zval* $id $name $dt zval zval zval MYSQLND_RES 3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” MySQL Server MEMORY POOL (use malloc) 38 line 1 internal buffers
  • 39. fetch * N zval* zval* zval* $id $name $dt zval zval zval MYSQLND_RES 3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” MySQL Server MEMORY POOL (use malloc) 39 line N internal buffers geting fat until statement released
  • 40. solution for reduced memory • use MYSQLI_STORE_RESULT_COPY_DATA – fetch with copy – php >= 5.6.0 – Not for PDO yet… – http://blog.ulf-wendel.de/2014/php-5- 7-mysqlnd-memory-optimizations/ 40
  • 41. fetch with copy zval zval zval no internal buffers 3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” MySQL Server MYSQLND_RES $id $name $dt 41 line N 123 “do_aki” “2014-10-11 11:30:00”
  • 43. fetch (text protocol) $id $name $dt mysqli/pdo 3 “123” 6 "do_aki” 19 “2014-10-11 11:30:00” MySQL Server mysqlnd 43
  • 44. fetch (binary protocol) $id $name $dt MySQL Server mysqlnd 123 6 "do_aki” 2014-10-11 11:30:00 mysqli/pdo 123 “do_aki” “2014-10-11 11:30:00” 44
  • 45. fetch (detail) zval* zval* zval* $id $name $dt zval zval zval MYSQLND_RES 123 “do_aki” “2014-10-11 11:30:00” 123 6 "do_aki” 2014-10-11 11:30:00 MySQL Server 45 line 1
  • 46. fetch*N zval* zval* zval* $id $name $dt zval zval zval MYSQLND_RES 111222333 “““dddooo___aaakkkiii””” ““2“2020101414-4-1-1010-0-1-1111 1 1 1111:1:3:3030:0:0:0000”0”” 123 “do_aki” “2014-10-11 11:30:00” 123 6 "do_aki” 2014-10-11 11:30:00 MySQL Server 46 line N
  • 47. fetch*N zval* zval* zval* $id $name $dt zval zval zval MYSQLND_RES 111222333 “““dddooo___aaakkkiii””” ““2“2020101414-4-1-1010-0-1-1111 1 1 1111:1:3:3030:0:0:0000”0”” 123 “do_aki” “2014-10-11 11:30:00” 123 6 "do_aki” 2014-10-11 11:30:00 MySQL Server 47 increases memory usage each fetch (until statement released) cannot use “MYSQLI_STORE_RE SULT_COPY_DATA” to prepared statement
  • 48. Conclusion • I explain mysqlnd • mysqlnd and libmysql work differently • use mysqli if you want to full functions of mysqlnd • Prepared statement…… 48
  • 49. Thank you 2014/10/11 PHP Conference Japan 2014 do_aki 49