PHP Client for Mysql Binlog
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP Client for Mysql Binlog,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3087字,纯文字阅读大概需要5分钟。
内容图文
![PHP Client for Mysql Binlog](/upload/InfoBanner/zyjiaocheng/455/974ed9968322418f9ade4061b922a5b3.jpg)
Install php-binlog
- https://github.com/bullsoft/php-binlog/archive/master.zip
unzip php-binlog-master.zip
cd php-binlog-master/ext
/usr/local/php5.5.15/bin/phpize
./configure --with-php-config=/usr/local/php5.5.15/bin/php-config --with-mysql-binlog=/usr/local/mysql-replication
Examples
注:Binlog为行格式
<?php
$link = binlog_connect("mysql://root:cpyf@127.0.0.1:3306");
//binlog_set_position($link, 4);
//binlog_set_position($link, 4, ‘mysql-bin.000006‘);
while($event=binlog_wait_for_next_event($link)) {
// it will block here
switch($event[‘type_code‘]) {
case BINLOG_DELETE_ROWS_EVENT:
var_dump($event);
// do what u want ...
break;
case BINLOG_WRITE_ROWS_EVENT:
var_dump($event);
// do what u want ...
break;
case BINLOG_UPDATE_ROWS_EVENT:
var_dump($event);
// do what u want ...
break;
default:
// var_dump($event);
break;
}
}
Update_rows
update `type` set type_id = 22 WHERE id in (58, 59);
array(5) {
‘type_code‘ =>
int(24)
‘type_str‘ =>
string(11) "Update_rows"
‘db_name‘ =>
string(5) "cloud"
‘table_name‘ =>
string(4) "type"
‘rows‘ =>
array(4) {
[0] =>
array(5) {
[0] =>
string(2) "58"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
[1] =>
array(5) {
[0] =>
string(2) "58"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(1) "4"
[4] =>
string(1) "0"
}
[2] =>
array(5) {
[0] =>
string(2) "59"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
[3] =>
array(5) {
[0] =>
string(2) "59"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(1) "4"
[4] =>
string(1) "0"
}
}
}
Delete_rows
delete from `type` WHERE id in (58, 59);
array(5) {
‘type_code‘ =>
int(25)
‘type_str‘ =>
string(11) "Delete_rows"
‘db_name‘ =>
string(5) "cloud"
‘table_name‘ =>
string(4) "type"
‘rows‘ =>
array(2) {
[0] =>
array(5) {
[0] =>
string(2) "58"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
[1] =>
array(5) {
[0] =>
string(2) "59"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
}
}
Write_rows
insert into type values (Null, "Hello, World", "Best world", 4, 0), (NULL, "你好,世界", "世界很美好", 3, 5);
array(5) {
‘type_code‘ =>
int(23)
‘type_str‘ =>
string(10) "Write_rows"
‘db_name‘ =>
string(5) "cloud"
‘table_name‘ =>
string(4) "type"
‘rows‘ =>
array(2) {
[0] =>
array(5) {
[0] =>
string(2) "95"
[1] =>
string(12) "Hello, World"
[2] =>
string(10) "Best world"
[3] =>
string(1) "4"
[4] =>
string(1) "0"
}
[1] =>
array(5) {
[0] =>
string(2) "96"
[1] =>
string(15) "你好,世界"
[2] =>
string(15) "世界很美好"
[3] =>
string(1) "3"
[4] =>
string(1) "5"
}
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
PHP Client for Mysql Binlog
标签:mysql binlog
本文系统来源:http://blog.csdn.net/jiao_fuyou/article/details/47615491
内容总结
以上是互联网集市为您收集整理的PHP Client for Mysql Binlog全部内容,希望文章能够帮你解决PHP Client for Mysql Binlog所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。