我有一个apphp_db_install($sql_dump_file)从 db_dump.sql 文件安装 sql 数据库的函数,我收到一个错误:SQLSTATE [42000]:语法错误或访问冲突:1065 查询为空我已经尝试在干净的数据库中使用此功能。我安装 SQL 的功能:function apphp_db_install($sql_dump_file) { global $error_mg; global $username; global $password; global $database_prefix; global $password_encryption; global $db; $sql_array = array(); $query = "";// get sql dump content $sql_dump = file($sql_dump_file);// replace database prefix if exists $sql_dump = str_ireplace('<DB_PREFIX>', $database_prefix, $sql_dump);// disabling magic quotes at runtime if(get_magic_quotes_runtime()){ function stripslashes_runtime(&$value){ $value = stripslashes($value); } array_walk_recursive($sql_dump, 'stripslashes_runtime'); }// add ";" at the end of file if(substr($sql_dump[count($sql_dump)-1], -1) != ";") { $sql_dump[count($sql_dump)-1] .= ";"; } // replace username and password if exists if(EI_USE_USERNAME_AND_PASWORD){ $sql_dump = str_ireplace("<USER_NAME>", $username, $sql_dump); if(EI_USE_PASSWORD_ENCRYPTION){ if($password_encryption == "AES"){ $sql_dump = str_ireplace("<PASSWORD>", "AES_ENCRYPT('".$password."', '".EI_PASSWORD_ENCRYPTION_KEY."')", $sql_dump); }else if($password_encryption == "MD5"){ $sql_dump = str_ireplace("<PASSWORD>", "MD5('".$password."')", $sql_dump); }else{ $sql_dump = str_ireplace("<PASSWORD>", "AES_ENCRYPT('".$password."', '".EI_PASSWORD_ENCRYPTION_KEY."')", $sql_dump); } }else{ $sql_dump = str_ireplace("<PASSWORD>", "'".$password."'", $sql_dump); } }else{ $sql_dump = str_ireplace("<USER_NAME>", "", $sql_dump); $sql_dump = str_ireplace("<PASSWORD>", "''", $sql_dump); } $sql_dump = str_ireplace("<ENCRYPTION_TYPE>", $password_encryption, $sql_dump);
1 回答
狐的传说
TA贡献1804条经验 获得超3个赞
您尝试执行的 SQL 转储中似乎有空行(因此该行的查询确实为空)
首先修复,测试$sql_line != ""
是无用的,因为file()
函数在每行的末尾返回行尾字符。您可以更换每个测试trim($sql_line) != ""
如果还不够,您可以添加一个测试(trim($sql_line) != ';')
以删除仅包含;
- 1 回答
- 0 关注
- 156 浏览
添加回答
举报
0/150
提交
取消