Home > Backend Development > PHP Tutorial > zend 获取安插数据的ID

zend 获取安插数据的ID

WBOY
Release: 2016-06-13 13:00:10
Original
782 people have browsed it

zend 获取插入数据的ID
怎么获得刚刚插入一条数据的主键id值?
------解决方案--------------------
$lastid=$db->lastInsertId();

这样就可以获得最近的id值了
------解决方案--------------------

引用:
怎么获得刚刚插入一条数据的主键id值?

正解。。。。。。顶了。。。。
------解决方案--------------------
<br />
//<br />
// INSERT INTO round_table<br />
//     (noble_title, first_name, favorite_color)<br />
//     VALUES ("King", "Arthur", "blue");<br />
//<br />
<br />
// 创建一个 $db对象, 然后...<br />
// 以"列名"=>"数据"的格式格式构造插入数组,插入数据行<br />
$row = array (<br />
    'noble_title'    => 'King',<br />
    'first_name'     => 'Arthur',<br />
    'favorite_color' => 'blue',<br />
);<br />
<br />
// 插入数据的数据表<br />
$table = 'round_table';<br />
<br />
// i插入数据行并返回行数<br />
$rows_affected = $db->insert($table, $row);<br />
$last_insert_id = $db->lastInsertId();<br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template