本文整理汇总了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;
}