我有一个存储在另一个站点的csv文件。 我构建了一个简单的查询,我想将第一列和第二列插入到我的表中。
当我进入我的php页面时,我可以看到消息" Connection已成功",它很好,但我没有任何消息,例如&# 34;插入失败"或者其他的东西。
我的表格中没有插入。
<?php
$fin = fopen('http://diederichs.com/reseller/RZZAQZYIJxPY6JxO/supply/csv','r') or die('cant open file');
try {
$link = new PDO('mysql:dbname=;host=localhost', '', '');
echo 'Connection succeeded <br />' . PHP_EOL;
$stmt = $db->prepare('INSERT INTO supply SET COL2 = :sku, reference = :reference');
//Only give the length parameter if you **KNOW** that no line will be longer than that
while (($data=fgetcsv($fin,1000,","))!==FALSE) {
if ($stmt->execute(array(':sku' => $data[1], ':reference' => $data[0]))) {
echo 'Insert ok<br />' . PHP_EOL;
} else {
$err = $stmt->errorInfo();
echo 'Insert Failed: ' . $err[2] . PHP_EOL;
}
}
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
fclose($fin);
?>
答案 0 :(得分:0)
您正在使用UPDATE语法,因为INSERT是
INSERT INTO supply(COL2,reference) VALUES(:sku,:reference)