Example on a new Row:
<?php
$sql = "INSERT INTO city (`city`) VALUES ('Paris') ON DUPLICATE KEY UPDATE `city` = 'Paris";
$dbh->query($sql);
echo $dbh->lastInsertId();
?>
Above displays: 1
Expected display: 1
Example on an existing row that gets updated:
<?php
$sql = "INSERT INTO city (`city`) VALUES ('Paris') ON DUPLICATE KEY UPDATE `city` = 'Paris";
$dbh->query($sql);
echo $dbh->lastInsertId();
?>
Above displays: 2
Expected display: 1 (since no new records were inserted)
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$stmt = $dbh->prepare("INSERT INTO test (name, email) VALUES(?,?)");
try {
$dbh->beginTransaction();
$tmt->execute( array('user', 'user@example.com'));
$dbh->commit();
print $dbh->lastInsertId();
} catch(PDOExecption $e) {
$dbh->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
} catch( PDOExecption $e ) {
print "Error!: " . $e->getMessage() . "</br>";
}
?>
строка состоящая из нескольких get параметров
$s = 'adfdf=1123&url=http://cs541207v4.vk.me/u63235608/videos/abbe4bbcd0.720.mp4?extra=qxzgmY36um2vOm3XmmutORuGfjwo__AWURSQcoEHnUn8BE54fPVJICkTDFpLfQ3SIdYn-nRUqjtlHo6R8brKHjZ3ChfTcY3x&c=3';
function parse($s)
{
$res = array();
foreach (explode('&',$s) as $tmp)
{
$tmp2 = explode('=',$tmp);
$key = $tmp2[0];
unset ($tmp2[0]);
$res[$key]=implode('=',$tmp2);
}
return $res;
}