gpt4 book ai didi

phpmyadmin 查询与 mysql 搜索表单和特殊字符

转载 作者:行者123 更新时间:2023-11-29 08:21:50 25 4
gpt4 key购买 nike

在 phpMyAdmin 中搜索“Loral's Library”,然后选择“创建 PHP 代码”时,我看到 phpMyAdmin 查询自动插入 ': 的转义字符

$sql = "SELECT * FROM `programs` WHERE `progname` LIKE \'Loral\'\'s Library\' LIMIT 0, 30 ";

如何在 mysql 搜索表单中包含相同的函数?

我对“Loral's Library”这样的表单的查询如下:

$query = "SELECT * FROM programs WHERE progname LIKE '$search' ORDER BY progname ASC";

该类型搜索对于任何带有 ' 字符的内容都会返回错误。在搜索表单中输入“Loral's Library”,然后将其传递到 search.php 文件以执行查询。

最佳答案

$escapedVaue=mysqli_real_escape_string($link,$originalValue);

该函数正是这样做的。

mysqli::real_escape_string -- mysqli_real_escape_string — Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection

This function is used to create a legal SQL string that you can use in an SQL statement. The given string is encoded to an escaped SQL string, taking into account the current character set of the connection.

Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.

mysqli_real_escape_string

关于phpmyadmin 查询与 mysql 搜索表单和特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19174409/

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