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