PHPClientforMysqlBinlog_MySQL

WBOY
풀어 주다: 2016-06-01 12:58:37
원래의
1162명이 탐색했습니다.

 

Install MySQL Replication Listener

https://github.com/bullsoft/mysql-replication-listener/archive/master.zip
<code class="hljs lasso">unzip mysql-replication-listener-master.zip
cd mysql-replication-listener-master
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-replication
make & make install</code>
로그인 후 복사

Install php-binlog

https://github.com/bullsoft/php-binlog/archive/master.zip
<code class="hljs lasso"><code class="hljs lasso">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</code></code>
로그인 후 복사

<code class="hljs lasso">Examples

<code class="hljs lasso">注:Binlog为行格式

<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><!--?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;
    }
}
</pre-->



</code></code></code>
로그인 후 복사

<code class="hljs lasso"><code class="language-php hljs ">Update_rows

<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs ">update `type` set type_id = 22 WHERE id in (58, 59);</code></code></code></code>
로그인 후 복사
<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs ">array(5) {
  &#39;type_code&#39; =>
  int(24)
  &#39;type_str&#39; =>
  string(11) "Update_rows"
  &#39;db_name&#39; =>
  string(5) "cloud"
  &#39;table_name&#39; =>
  string(4) "type"
  &#39;rows&#39; =>
  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"
    }
  }
}</code></code></code></code></code>
로그인 후 복사

<code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs ">Delete_rows

<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs ">delete from `type` WHERE id in (58, 59);</code></code></code></code></code></code>
로그인 후 복사
<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs ">array(5) {
  &#39;type_code&#39; =>
  int(25)
  &#39;type_str&#39; =>
  string(11) "Delete_rows"
  &#39;db_name&#39; =>
  string(5) "cloud"
  &#39;table_name&#39; =>
  string(4) "type"
  &#39;rows&#39; =>
  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"
    }
  }
}</code></code></code></code></code></code></code>
로그인 후 복사

<code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs ">Write_rows

<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs ">insert into type values (Null, "Hello, World", "Best world", 4, 0), (NULL, "你好,世界", "世界很美好", 3, 5);</code></code></code></code></code></code></code></code>
로그인 후 복사
<code class="hljs lasso"><code class="hljs lasso"><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs "><code class="language-sql hljs "><code class="language-php hljs ">array(5) {
  &#39;type_code&#39; =>
  int(23)
  &#39;type_str&#39; =>
  string(10) "Write_rows"
  &#39;db_name&#39; =>
  string(5) "cloud"
  &#39;table_name&#39; =>
  string(4) "type"
  &#39;rows&#39; =>
  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"
    }
  }
}</code></code></code></code></code></code></code></code></code>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿