duana1021 2017-01-05 17:02
浏览 39

执行包含URL编码字符串的MySQLi搜索

I am having trouble retrieving data from a database, when the field contains a URL encoded string.

What I mean is, my MySQLi database contains a field called "artist_name", where some of the values contain URL encoded strings, such as:

  • "Sonny+O'Brien"
  • "Lil'+Joe"
  • "Batman+&+Robin"

etc.

When I search on these fields in PhpMyAdmin, it finds them straight away, using a select statement:

SELECT * FROM `artists` WHERE `artist_name` LIKE 'Sonny+O'Brien';

However, when I try the same thing programmatically, from within my PHP script, it returns no results:

$artist_name = "Sonny+O'Brien";
$sql = "SELECT * FROM artists WHERE artist_name LIKE '".$artist_name."'";
if ( $result = $mysqli->query( $sql ) ) {
    $obj = $result->fetch_object();
}

No results.

I have tried using an addslashes() on the artist's name, and I have double-checked all the value's and I am providing them exactly as they appear in the database.

Any ideas why the URL escaped strings are not recognised in my SELECT queries?

edit: screenshot (screenshot from PhpMyAdmin, showing that my data is stored as described, and that my SELECT query works from within PhpMyAdmin, just not from my PHP script).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录