茂名网站制作,网络ui设计培训班,大连seo顾问,商城app开发费用多少钱php 数据库pdo对象#xff0c;如果是返回#xff0c;如以下伪代码 function getData(){ return $data; } $data getData(); $id $data-lastInsertId(); 此时会获取不到#xff0c;因为mysql的lastInsertId是和连接相关的#xff0c;我猜想是返回后#xff0c;这个数… php 数据库pdo对象如果是返回如以下伪代码 function getData(){ return $data; } $data getData(); $id $data-lastInsertId(); 此时会获取不到因为mysql的lastInsertId是和连接相关的我猜想是返回后这个数据库连接已经不是操作数据时的连接了。 解决方法 1、在返回前赋值 function getData(){ $data-id $data-lastInsertId(); return $data; } 2、用uuid替代lastInsertId。如果遇到多线程的问题有可能这个id是错误的。 function getData(){ $data-uuid getUUID(); return $data; }转载于:https://www.cnblogs.com/xdao/p/php_lastInsertId.html