我正在兩個平臺上工作。一個是裝有XAMPP的Windows 10計算機,另一個是裝有缺省Apache,PHP和MySQL的Mac OS X El Capitan。目標是將從遠程服務器下載的.sql文件導入本地服務器。代碼如下:mysqli multi_query只能在XAMPP中使用?
$dbhost = 'localhost';
$dbuser = 'someuser';
$dbpass = 'somepassword';
$dbname = 'somedb';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$filename = "somesql.sql";
$sqlSource = file_get_contents($filename);
$cmp = $mysqli->multi_query($sqlSource);
if($cmp){ $message = 'Import Successful'; }
else{ $message = 'Import Unsuccessful | '.$mysqli->error; }
然而,上述代碼在XAMPP工作在Windows 10計算機上,但不能在Mac OS X.在Mac OS X,它在某種程度上僅執行了從CREATE TABLE語句tablename
.sql文件但不包含INSERT INTO表名VALUES位。它不會產生任何錯誤。
它也不能在Windows中使用Apache,PHP和MySQL單獨安裝。
有沒有我錯過的或者是否有一個配置,我需要調整,使其在Mac OS X上工作?
編輯:下面是生成的SQL文件,somesql.sql:
CREATE TABLE `sometable` (
`id` smallint(9) unsigned NOT NULL AUTO_INCREMENT,
`var_1` varchar(200) DEFAULT NULL,
`var_2` varchar(200) DEFAULT NULL,
`var_3` varchar(200) DEFAULT NULL,
`int_1` int(100) DEFAULT NULL,
`int_2` int(100) DEFAULT NULL,
`int_3` int(100) DEFAULT NULL,
`text_1` text COMMENT 'depot address',
`text_2` text,
`text_3` text,
`decimal_1` decimal(10,2) DEFAULT NULL,
`decimal_2` decimal(10,2) DEFAULT NULL,
`decimal_3` decimal(10,2) DEFAULT NULL,
`datetime_1` datetime DEFAULT NULL,
`datetime_2` datetime DEFAULT NULL,
`datetime_3` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `var_1` (`var_1`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
INSERT INTO sometable VALUES
("2","BN","","","","","","Some details","","","","","","","",""),
("3","MK","","","","","","Some other details","","","","","","","",""),
("4","CH","","","","","","Some other other details","","","","","","","","");
檢查'file_get_contents'它返回什麼? – Saty
發佈'somesql.sql'文件的代碼以及 – Nehal
@Saty我已編輯帖子以包含生成的sql文件。 – ddz1507