zend 获取插入数据的ID解决办法

WBOY
Release: 2016-06-13 13:45:14
Original
852 people have browsed it

zend 获取插入数据的ID
怎么获得刚刚插入一条数据的主键id值?

------解决方案--------------------
$lastid=$db->lastInsertId();

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

探讨
怎么获得刚刚插入一条数据的主键id值?

------解决方案--------------------
PHP code

//
// INSERT INTO round_table
//     (noble_title, first_name, favorite_color)
//     VALUES ("King", "Arthur", "blue");
//

// 创建一个 $db对象, 然后...
// 以"列名"=>"数据"的格式格式构造插入数组,插入数据行
$row = array (
    'noble_title'    => 'King',
    'first_name'     => 'Arthur',
    'favorite_color' => 'blue',
);

// 插入数据的数据表
$table = 'round_table';

// i插入数据行并返回行数
$rows_affected = $db->insert($table, $row);
$last_insert_id = $db->lastInsertId(); <div class="clear">
                 
              
              
        
            </div>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!