Home > Zend framework > Zend framework last insert id

Zend framework last insert id

Zend framework version < 2

Cách 1 Để lấy thông tin last insert id tại controller:


$my_model = new my_model()
$my_model->insert($my_param)

$last_id = $my_model->getAdapter()->lastInsertId();

//Out put primary bạn vừa insert

Cách 2 hoặc tại model


$sql = "INSERT INTO table (field) VALUE('123')";
$this->getAdapter()->query($sql);
$last_id = $this->getAdapter()->lastInsertId();
return $last_id

Lưu ý:
Để gọi được hàm lastInsertId(); thiết kế CSDL khóa chính (primary key phải để thuộc tính AUTO_INCREMENT)

nhantam
PHP Developer
http://www.panpic.vn

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: