gpt4 book ai didi

php - 在 Codeigniter 中使用 UNION 并出现错误?

转载 作者:行者123 更新时间:2023-11-29 06:13:44 25 4
gpt4 key购买 nike

我想使用UNION选择数据,如下所示:

$find = 'hello';
$data = $this->db->query('SELECT * FROM tour_foreign_residence WHERE name LIKE '%$find%' UNION SELECT * FROM tour_foreign WHERE name LIKE '%$find%''); // Line number 46

但是我遇到了这个错误:

> A PHP Error was encountered<br> Severity: Warning<br> Message:
> Division by zero<br> Filename: foreign.php<br> Line Number: 46<br>
>
> A Database Error Occurred<br> The query you submitted is not
> valid.<br> Filename:
> D:\xampp\htdocs\system\database\DB_driver.php<br> Line
> Number: 257<br>

如何修复它?

更新:

错误:

> A Database Error Occurred<br> Error Number: 1222<br> The used SELECT
> statements have a different number of columns<br> SELECT * FROM
> tour_foreign_residence WHERE name LIKE "%hello%" UNION SELECT * FROM
> tour_foreign WHERE name LIKE "%hello%"<br> Filename:
> D:\xampp\htdocs\system\database\DB_driver.php<br> Line Number: 330<br>

最佳答案

您在字符串中添加单引号而不转义它们。这可能是你的问题。

关于php - 在 Codeigniter 中使用 UNION 并出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7803176/

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