Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用未定义函数mysqli\u begin\u transaction()时出错_Php_Mysql - Fatal编程技术网

Php 调用未定义函数mysqli\u begin\u transaction()时出错

Php 调用未定义函数mysqli\u begin\u transaction()时出错,php,mysql,Php,Mysql,我正在使用一个php脚本来处理数据库的备份和恢复。它有几个问题,但我将一次发布一个错误。单击“还原备份”按钮时,标题中出现了错误 我没有足够的经验来解决这个错误,并将感谢一些专家的帮助。我已经将我的代码张贴在错误发生的地方,但是如果您需要查看其他内容,请告知。错误发生在第109行。谢谢 PHPV5.3.13 MYSQL V5.5.24 APACHE V2.2.22 <?php function restoredata($uploadedfile, &$ustartindex, &

我正在使用一个php脚本来处理数据库的备份和恢复。它有几个问题,但我将一次发布一个错误。单击“还原备份”按钮时,标题中出现了错误

我没有足够的经验来解决这个错误,并将感谢一些专家的帮助。我已经将我的代码张贴在错误发生的地方,但是如果您需要查看其他内容,请告知。错误发生在第109行。谢谢

PHPV5.3.13 MYSQL V5.5.24 APACHE V2.2.22

<?php

function restoredata($uploadedfile, &$ustartindex, &$uti, &$ulen, &$ucount, &$name, &$limit, $restoremethod)
{
 global $host, $username, $passwd, $charset, $port, $upload_path, $backup_path;
 $sql = '';
 $zip = new ZipArchive();
 $filename = $upload_path . '/' . $uploadedfile;
 if (!is_file($filename)) {
  $filename = $backup_path . '/' . $uploadedfile;
 }

 if ($zip->open($filename) !== TRUE) {
  return "Cannot open file\n.";
 }

 try {
  $dbName = $zip->getFromName('database.txt');
  if ($restoremethod == '0') {
   $conn = mysqli_connect($host, $username, $passwd, $dbName, $port);
  }
  else {
   if ($uti == 0 && $ustartindex == 0) {
    $conn = mysqli_connect($host, $username, $passwd, 'mysql', $port);
   }
   else {
    $conn = mysqli_connect($host, $username, $passwd, $dbName, $port);
   }
  }

  if (!$conn) {
   return 'Could not connect ' . mysqli_error($conn);
  }

  if (!mysqli_set_charset($conn, $charset)) {
   mysqli_query($conn, 'SET NAMES ' . $charset);
  }

  $tables = $zip->getFromName('tables.txt');
  if ($tables === false) {
   $zip->close();
   return "Could'nt find tables";
  }

  $limit = intval($zip->getFromName('limit_info.txt'));
  $tables = explode(',', $tables);
  $ulen = count($tables);
  if ($uti < $ulen) {
   if ($uti == 0 && $ustartindex == 0) {
    if ($restoremethod == '1') {
     $sql = $zip->getFromName($dbName . '.sql');
     if ($sql !== false) {
      $sql = explode(';' . chr(10) , $sql);
      for ($i = 0; $i < count($sql) - 1; $i++) {
       $result = mysqli_query($conn, $sql[$i] . ';');
       if (!$result) {
        mysqli_close($conn);
        $zip->close();
        return 'Could not run query 1: ' . mysqli_error($conn);
       }
      }
     }

     mysqli_close($conn);
     $conn = mysqli_connect($host, $username, $passwd, $dbName, $port);
     if (!$conn) {
      $zip->close();
      return 'Could not connect ';
     }

     for ($i = 0; $i < $ulen; $i++) {
      $name = $tables[$i];
      $table = '`' . $name . '`';
      $sql = $zip->getFromName($table . '.sql');
      if ($sql !== false) {
       $sql = explode(';' . chr(10) , $sql);
       for ($j = 0; $j < count($sql) - 1; $j++) {
        $result = mysqli_query($conn, $sql[$j] . ';');
        if (!$result) {
         mysqli_close($conn);
         $zip->close();
         return 'Could not run query 2: ' . mysqli_error($conn);
        }
       }
      }
     }
    }
   }

   mysqli_autocommit($conn, FALSE);

   // mysqli_begin_transaction ($conn, MYSQLI_TRANS_START_READ_ONLY );//READ ONLY transaction 

   mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_WRITE); <---ERROR HERE
   $name = $tables[$uti];
   $table = '`' . $name . '`';
   $ucount = intval($zip->getFromName($table . '.txt'));
   $sql = $tables = $zip->getFromName($table . '/offset' . $ustartindex . '.sql');
   $nerrors = 0;
   $serrors = '';
   if ($sql !== false) {
    $sql = explode(';' . chr(10) , $sql);
    for ($i = 0; $i < count($sql) - 1; $i++) {
     $sql[$i] = str_replace('NULL', "''", $sql[$i]); //avoid NULL errors
     $result = mysqli_query($conn, $sql[$i] . ';');
     if (!$result) {
      $serrors.= 'Could not run query in ' . $table . ' : ' . mysqli_error($conn) . '<br />';
      $nerrors+= 1;
      break;
     }
    }

    $ustartindex+= $limit;
   }
   else {
    $uti+= 1;
    $ustartindex = 0;
   }

   if (!mysqli_commit($conn)) {
    return "Transaction commit failed";
   }

   if ($nerrors > 0) {
    mysqli_close($conn);
    $zip->close();
    return $serrors;
   }
  }

  mysqli_close($conn);
  $zip->close();
 }

 catch(Exception $e) {
  return var_dump($e->getMessage());
 }

 return true;
}
?>
I will add that this is not my script but it does all all I need it to do including showing the progress of the backup, which visually is better than just a white page.

I would if possible like to sort these errors out and have a working script. Many thanks. 
从,mysqli_begin_事务仅在PHP5.5.0以后支持。因为你的跑步5.3不起作用

您可以删除该事务,它将起作用,特别是当您最初尝试设置只读事务时。还要删除提交

我将删除以下行,因为这将依赖于事务按照您的预期工作

mysqli_autocommit($conn, FALSE);
如果您需要继续使用5.3,那么

mysqli_query($conn, "START TRANSACTION");

您正在运行哪个版本的PHP?@Nigel PHP V5.3.13From,mysqli_begin_transaction-PHP 5>=5.5.0,PHP7@Nigel这是否意味着我必须有最低的php版本5.5.0?不幸的是,是的,但这是一个更新的机会。如果您需要运行此代码,只需删除它。非常感谢nigel。该代码是否用于mysqli_查询($conn,“启动事务”);转到mysqli_begin_事务所在的位置。