mysql insert id pdo_MySQL PDO最后插入了ID

我有一个带有主键的MySQL表,我插入到那个表中,我想恢复最后一行的id已插入,我知道我必须使用LAST_INSERT_ID

但我的问题是在使用该语句将值插入到另一个没有主键的表后,我可以再次使用它来获取第一个插入的确切ID吗?

$php pdo#

include_once 'type_model.php';

$t = new Type_Model();

$typeID = $t->getTypeID($type);

include_once 'informationObject_model.php';

$i = new InformationObject_Model();

$answerIoID = $i->getIOID($ioAnswer);

$query = "INSERT INTO question (info, text, answer, answerIoID, firstChoice, secondChoice, thirdChoice,

firstHint, secondHint, typeID) VALUES (:info, :text, :answer, :answerIoID,

:firstChoice, :secondChoice, :thirdChoice, :firstHint, :secondHint, :typeID)";

$sth = $this->db->prepare($query);

$sth->execute(array(

':info' => $info,

':text' => $text,

':answer' => $answer,

':answerIoID' => $answerIoID,

':firstChoice' => $choices[0],

':secondChoice' => $choices[1],

':thirdChoice' => $choices[2],

':firstHint' => $hints[0],

':secondHint' => $hints[1],

':typeID' => $typeID

));

if ($about == "Place") {

include_once 'place_model.php';

$p = new Place_Model();

$placeID = $p->getPlaceID($place);

$query = "INSERT INTO `question-place` (questionID, placeID) VALUES

(LAST_INSERT_ID() ,:placeID )";

$sth = $this->db->prepare($query);

$sth->execute(array(

':placeID' => $placeID

));

}

现在,如果关于==地方可以写这个吗?

$query = "INSERT INTO `question-io` (questionID, io) VALUES

(LAST_INSERT_ID() ,:io )";

$sth = $this->db->prepare($query);

$sth->execute(array(

':io' => $io

));

我没有尝试过,因为我无法尝试,直到我填写所有表格而且我无法填写所有表格而不知道ID ?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要安装pdo_mysql驱动,你可以按照以下步骤进行操作: 1. 打开终端,并进入pdo_mysql驱动的源代码目录。 2. 运行以下命令来配置编译选项: ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql 这里的"/usr/local/php/bin/php-config"是你的PHP可执行文件的路径,而"/usr/local/mysql"是你的MySQL安装路径。\[1\]\[2\]\[3\] 3. 运行以下命令进行编译: make 4. 运行以下命令进行安装: make install 5. 最后,你需要在PHP的配置文件中启用pdo_mysql扩展。你可以编辑php.ini文件,并添加以下行: extension=pdo_mysql.so 保存文件并退出。 完成以上步骤后,pdo_mysql驱动就会成功安装并启用。请确保你的PHP和MySQL的版本兼容,并且已经正确安装了相应的依赖库。 #### 引用[.reference_title] - *1* [详解php7安装 pdo_mysql 扩展](https://blog.csdn.net/weixin_28990495/article/details/116945545)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [linux安装php pdo扩展,linux下php安装pdo_mysql扩展](https://blog.csdn.net/weixin_30269739/article/details/115948803)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值