在PHP扩展中读取更新的参考值

时间:2019-05-07 12:56:39

标签: php php-extension

我正在编写一个PHP扩展来跟踪数据库调用和mysqli扩展的检索数据。为此,我更新了mysqli :: bind_result和mysqli :: fetch方法的方法处理程序,并引入了代理方法。

现在在mysqli :: bind_result的代理方法中,我保持输入引用如下所示:

void proxy_mysqli_stmt_bind_result(INTERNAL_FUNCTION_PARAMETERS)
{
    original_bind_result(INTERNAL_FUNCTION_PARAM_PASSTHRU);

    zval *args;
    int argc;
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/+", &args, &argc) == FAILURE) 
    {
       return;
    }

    HOOK_MYSQLI_G(args) = args;
    HOOK_MYSQLI_G(argc) = argc;        
}

在mysqli :: fetch的代理方法中,我正在读取更新的值-

void proxy_mysqli_stmt_fetch(INTERNAL_FUNCTION_PARAMETERS)
{
   original_fetch(INTERNAL_FUNCTION_PARAM_PASSTHRU);

   if (Z_TYPE_P(return_value) != IS_TRUE) return;

   zval *args = HOOK_MYSQLI_G(args);
   int  argc = HOOK_MYSQLI_G(argc);

   for (size_t i = 0; i < argc; i++)
   {
       log("%s", Z_STRVAL_P(Z_REFVAL_P(&args[i]));
   }
}

PHP脚本-

$mysqli = new mysqli($host, $username, $password);
$mysqli->select_db($dbname);

$stmt = $mysqli->prepare($sql);
$stmt->execute();
$stmt->bind_result($id, $firstname, $lastname);

while ($stmt->fetch()) {
    printf ("%s (%s)\n", $firstname, $location);
}

我在数据库中有两条记录用于测试。我的扩展名在日志文件中的输出(错误输出)

  

第一条记录:id1,name1,lastname1

     

第二条记录:%s(%s)\ n,name1,lastname1

如果我从php脚本中删除了printf,则输出符合预期-

  

第一条记录:id1,name1,lastname1

     

第二条记录:id2,name2,lastname2

这是什么问题?我为bind_result / fetch方法保留引用变量,为什么printf方法正在更新引用?

0 个答案:

没有答案