文字

mysqlnd_ms_get_last_gtid

(PECL mysqlnd_ms >= 1.2.0)

mysqlnd_ms_get_last_gtid返回最后的全局同步 ID (GTID)

说明

string mysqlnd_ms_get_last_gtid ( mixed $connection )

返回最后一次写操作以后的 GTID,他并不能保证一定是那次写操作产生的 GTID,但是得到的 GTID 一定比这次写操作产生的 GTID 大。

参数

connection

由 PDO_MYSQL, mysqli> 或者 ext/mysql 产生的 MySQL 服务器连接, 这些链接受 PECL/mysqlnd_ms 连接控制。连接的创建是通过 mysqlnd_ms 配置文件中 约定的群组名称建立的。

返回值

成功返回 GTID,失败返回 FALSE

函数通过配置文件中 global_transaction_id_injection 章节定义的 fetch_last_gtid 参数来获取 GTID。

在函数调用的时候,GTID 可能已经增加了。

注释

Note:

函数需要 PHP >= 5.4.0 版本,PECL/mysqlnd_ms >= 1.2.0 版本,在 PHP 5.3 版本中 mysqlnd 库不能使用。

范例

Example #1 mysqlnd_ms_get_last_gtid() example

<?php

$mysqli  = new  mysqli ( "myapp" "username" "password" "database" );
if (!
$mysqli )
  

  
die( sprintf ( "[%d] %s\n" mysqli_connect_errno (),  mysqli_connect_error ()));


if (! $mysqli -> query ( "DROP TABLE IF EXISTS test" ))
  die(
sprintf ( "[%d] %s\n" $mysqli -> errno $mysqli -> error ));

printf ( "GTID after transaction %s\n" mysqlnd_ms_get_last_gtid ( $mysqli ));


if (! $mysqli -> query ( "CREATE TABLE test(id INT)" ))
  die(
sprintf ( "[%d] %s\n" $mysqli -> errno $mysqli -> error ));

printf ( "GTID after transaction %s\n" mysqlnd_ms_get_last_gtid ( $mysqli ));
?>

参见

  • Global Transaction IDs
上一篇: 下一篇: