MySQL INSERT from a SELECT with PDO(MySQL 从带有 PDO 的 SELECT 插入)
问题描述
我在使用 PHP PDO 从 SELECT 查询中插入 INSERT 时有一个奇怪的行为.直接在 MySQL 中测试查询效果很好,我插入了我的行:
I have a strange behaviour using PHP PDO for a INSERT from a SELECT query. Testing the query directly in MySQL it works well, I get my row inserted :
INSERT INTO sessionid (enc_id, enc_pass, enc_date)
SELECT AES_ENCRYPT(username, 'aeskey'), AES_ENCRYPT(pwd, 'aeskey'),
DATE_ADD(NOW(), INTERVAL 15 SECOND) FROM users WHERE username = 'a_user_name';
但是使用 PDO,我为每个用户一次插入一行(279 行)......这是 PHP :
But using PDO, I have one row per user inserted at once (279 rows) .... Here is the PHP :
$sql_enc = '
INSERT INTO sessionid (enc_id, enc_pass, enc_date)
(SELECT AES_ENCRYPT(username, :aeskey), AES_ENCRYPT(pwd, :aeskey), DATE_ADD(NOW(), INTERVAL 15 SECOND) FROM users WHERE username = :username)
';
$res_enc = $pdo->prepare($sql_enc);
$res_enc->bindParam(':aeskey', $aeskey);
$res_enc->bindParam(':username', $username);
$res_enc->bindParam(':pwd', $username);
$res_enc->execute();
$res_enc = null;
我错过了什么?我几乎可以肯定它什么都不是,但不能让它插入那一行.
What am I missing? I'm almost sure it's nothing but can't make it insert that single row.
谢谢.
法比恩.
推荐答案
这不是可能的问题,而是您在代码的密码字段中输入了用户名.在您的查询中,您在那里插入 aeskey.这是我能发现的唯一区别.
Not that it is the probable problem, but you put a username in the password field in your code. In your query you insert the aeskey there. It is the only difference I can spot.
这篇关于MySQL 从带有 PDO 的 SELECT 插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 从带有 PDO 的 SELECT 插入
基础教程推荐
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
