我有这样的查询:
$modifiedDate1 = date("F d Y H:i:s.", filemtime($file));
$query = "INSERT IGNORE INTO file (filename, modifiedDate1) VALUES ".implode(',', $filenames)."".$modifiedDate1."";
我的SQL语法中出现第二个值的错误,为什么?
错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'January 01 1970 01:00:00.' at line 1
如果它有助于整个代码:
$pdo = new PDO('mysql:host=localhost;dbname=check', 'root', 'root');
if ($handle = opendir('check')) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if($file!='.' && $file!='..') {
$filenames[] = "('".$file."')";
}
}
closedir($handle);
}
$modifiedDate1 = date("F d Y H:i:s.", filemtime($file));
/* insert new record into the table filenames with the filename */
$query = ("INSERT IGNORE INTO file (filename,modifiedDate1) VALUES ('".implode(',', $filenames)."".$modifiedDate1."')");
$stmt = $pdo->exec($query);
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($pdo->errorInfo());
}
print "finished installing your files!";
此代码用于比较文件数据是否已存在于数据库中。