Home >Backend Development >PHP Tutorial >The source command cannot be used?

The source command cannot be used?

WBOY
WBOYOriginal
2016-10-19 10:40:481390browse

Can’t import? ? ?

<code>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</code>
<code class="php">
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();
  }
}
</code>

Note: There is no problem importing the package:

The source command cannot be used?

Reply content:

Can’t import? ? ?

<code>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</code>
<code class="php">
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();
  }
}
</code>

Note: There is no problem importing the package:

The source command cannot be used?

execute() can only execute SQL statements, and although SOURCE can also be executed in mysqlclient, it is not a sql statement, so d will fail to execute. It is recommended to directly use PHP’s exec command to execute it

Before importing, please check which library to use first. When I use cmd, I need to replace the slash in the path with a backslash to see if I will get an error. I hope it will be helpful to you

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn