無法導入? ? ?
<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>
註:導入包沒問題:
無法導入? ? ?
<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>
註:導入包沒問題:
execute()
只能執行SQL語句,而SOURCE
雖然也能在mysqlclient
中執行,但是並不是sql語句,所以d會執行失敗,建議直接用php的exec
指令執行
導入前的先use一下哪個庫吧,我用cmd都需要把路徑的斜線換成反斜線要不會報錯,希望對你有幫助