gpt4 book ai didi

MySQL批处理和连接: is it possible using SQL file injection?

转载 作者:行者123 更新时间:2023-11-29 09:01:30 25 4
gpt4 key购买 nike

这是我的表格示例:

mysql> select * from table_a where description='Auto';
+----+----------+-------------+-----------------+
| id | idparent | description | description_url |
+----+----------+-------------+-----------------+
| 11 | NULL | Auto | NULL |
| 74 | 73 | Auto | NULL |
+----+----------+-------------+-----------------+
2 rows in set (0.00 sec)

mysql>

现在,我将另一条记录插入到另一个表中,并记住它最后插入的 ID:

INSERT INTO table_b (description) values ('Myvalue');
set @lt=LAST_INSERT_ID();

现在我已经输入了@lt值。我可以做到这一点(并且它有效):

INSERT INTO table_a_link_b (id_a, id_b) VALUES (11, @lt);
INSERT INTO table_a_link_b (id_a, id_b) VALUES (74, @lt);

现在以下内容不起作用:

INSERT INTO table_a_link_b (id_a, id_b) VALUES
( (SELECT id FROM table_a where description='Auto') , @lt);

所以我尝试将其放入变量中:

mysql> set @t=(select id from table_a where description='Auto');
ERROR 1242 (21000): Subquery returns more than 1 row

这不起作用。有没有一种方法可以让我无需制作 Php 批处理文件并保持 SQL?

最佳答案

INSERT INTO table_a_link_b (id_a, id_b)
SELECT id,@lt FROM table_a where description='Auto';

关于MySQL批处理和连接: is it possible using SQL file injection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8450591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com