本文整理匯總了PHP中dbconnection::getLastInsertId方法的典型用法代碼示例。如果您正苦於以下問題:PHP dbconnection::getLastInsertId方法的具體用法?PHP dbconnection::getLastInsertId怎麽用?PHP dbconnection::getLastInsertId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dbconnection
的用法示例。
在下文中一共展示了dbconnection::getLastInsertId方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
public function save()
{
$connection = new dbconnection();
if ($this->id) {
$sql = "update jabaianb." . get_class($this) . " set ";
$set = array();
foreach ($this->data as $att => $value) {
if ($att != 'id' && $value) {
$set[] = "{$att} = '" . $value . "'";
}
}
$sql .= implode(",", $set);
$sql .= " where id=" . $this->id;
} else {
$sql = "insert into jabaianb." . get_class($this) . " ";
$sql .= "(" . implode(",", array_keys($this->data)) . ") ";
$sql .= "values ('" . implode("','", array_values($this->data)) . "')";
}
$connection->doExec($sql);
/*
* Sans cette modiffication, on recevait une erreur après un UPDATE:
* Object not in prerequisite state: 7 ERROR: currval of sequence "post_id_seq" is not yet defined in this session
*/
if (!$this->id) {
$this->id = $connection->getLastInsertId("jabaianb." . get_class($this));
}
return $this->id == false ? NULL : $this->id;
}
示例2: save
public function save()
{
$connection = new dbconnection();
if (isset($this->id)) {
$sql = "update jabaianb." . get_class($this) . " set ";
$set = array();
foreach ($this->data as $att => $value) {
if ($att != 'id' && $value) {
$set[] = "{$att} = '" . $value . "'";
}
}
$sql .= implode(",", $set);
$sql .= " where id=" . $this->id;
} else {
$sql = "insert into jabaianb." . get_class($this) . " ";
$sql .= "(" . implode(",", array_keys($this->data)) . ") ";
$sql .= "values ('" . implode("','", array_values($this->data)) . "')";
}
//print_r($sql);
$connection->doExec($sql);
$id = $connection->getLastInsertId("jabaianb." . get_class($this));
//print_r($id);
return $id == false ? NULL : $id;
}