提问人:user2751691 提问时间:2/22/2019 更新时间:2/22/2019 访问量:139
MySql 将 url 从 php 传递到数据库
MySql pass url from php to database
问:
在我的代码中,我有一个 sql 字符串php
select * from tablename where url in (%s)
;
我正在构造输入数组,它是 url 字符串的数组。urls
$urls = array("https://www.example.com", "https://www.example.com/try002");
我尝试了多种方法,但没有运气。
方法1:
$inputParams = array(implode(", ", $urls));
这给了我错误You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '://www.example.com,https://www.example.com/photos/try002)'
方法2:
所以我尝试添加双引号和单转义引号,因为当我尝试在 sql db 中时,可以工作。select * from tablename where url in ("https://www.example.com", "https://www.example.com/blabla")
foreach($urls as &$url)
{
$url = "'" . urlencode($url) . "', ";
}
$inputParams = array($urls);
双引号或单引号都不起作用。它产生 \“https://example.com\” 的查询,select * from tablename where url in (
"www.example.com/blabla")
我应该如何制定我的输入网址,以便我可以得到类似 please 的东西?select * from tablename where url in ("https://www.example.com", "https://www.example.com/blabla")
非常感谢。
答: 暂无答案
评论
mysqli
和 PDO 中非常简单,其中任何用户提供的数据都指定了一个 or 指示符,稍后使用 or 填充该指示符,具体取决于您使用的指示符。?
:name
bind_param
execute
$inputParams = array(implode(", ", $urls));
$inputParams = "'" . array(implode("', '", $urls)). "'";