Created
February 23, 2012 16:12
-
-
Save chonthu/1893479 to your computer and use it in GitHub Desktop.
on_duplicate_update 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO | |
`product` | |
SET | |
`id`=? | |
,`name`=? | |
,`created_at`=NOW() | |
ON DUPLICATE KEY UPDATE | |
,`name`=? | |
'; | |
$stmt = mysqli_prepare($dbh, $sql); | |
foreach ($products as $p) { | |
mysqli_stmt_bind_param($stmt, 'ss'.'ss', | |
$p['id'] | |
,$p['name'] | |
,$p['name'] | |
); | |
$success = mysqli_stmt_execute($stmt); | |
$err = mysqli_error($dbh); | |
if (!$success && strpos($err, 'Duplicate entry')) { | |
echo "Error inserting product: "; | |
echo $err; | |
echo PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment