Home >Backend Development >PHP Tutorial >The source command cannot be used?
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:
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:
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