欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

source 命令无法使用?

程序员文章站 2022-05-24 09:56:01
...

无法导入???

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'source D:\Server\three\public\export.sql' at line 1

function ImportDB($dbh) {
  $sql = 'source '.realpath('export.sql');
  try {
    $stmt = $dbh->prepare($sql);
    var_dump($stmt->execute());
    var_dump($stmt->errorInfo());
  }
  catch (PDOException $e) {
    print $e->getMessage();
  }
}

注:导入包没问题:

source 命令无法使用?

回复内容:

无法导入???

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'source D:\Server\three\public\export.sql' at line 1

function ImportDB($dbh) {
  $sql = 'source '.realpath('export.sql');
  try {
    $stmt = $dbh->prepare($sql);
    var_dump($stmt->execute());
    var_dump($stmt->errorInfo());
  }
  catch (PDOException $e) {
    print $e->getMessage();
  }
}

注:导入包没问题:

source 命令无法使用?

execute()只能执行SQL语句,而SOURCE虽然也能在mysqlclient中执行,但是并不是sql语句,所以d会执行失败,建议直接用php的exec命令进行执行

导入前的先use一下哪个库吧,我用cmd都需要把路径的斜线换成反斜线要不会报错,希望对你有帮助

相关标签: php mysql