2

我正在尝试从 fullName LIKE 'Ma%' 的数据库中选择前 10 个结果

它一直没有返回任何结果。我 100% 确定表中有一些结果,因为当我在不使用 mysqli ans 的情况下运行相同的查询时,它可以工作!

这段代码是怎么回事?有什么诀窍可以让这段代码运行吗?

这是我到目前为止所拥有的

$term = "'Ma%'";


$query = $db->prepare('SELECT customerID, fullName, birthYear, homeAddress, ID, DATE_FORMAT(idIssue, "%d-%m-%Y") AS idIssue, DATE_FORMAT(idExp, "%d-%m-%Y") AS idExp, phone
                       FROM customers WHERE (fullName LIKE ? ) LIMIT 0,10');
$query->bind_param('s', $term);

$query->execute();
4

1 回答 1

3
$term = "Ma%"; // <-- remove the extra quotes

$sql = 'SELECT customerID, fullName, birthYear, homeAddress, ID, phone, 
               DATE_FORMAT(idIssue, "%d-%m-%Y") AS idIssue, 
               DATE_FORMAT(idExp, "%d-%m-%Y") AS idExp
        FROM customers WHERE fullName LIKE ? LIMIT 0,10'
$query = $db->prepare($sql);
$query->bind_param('s', $term);
// s refers to a string, i for an int... etc.
$query->execute();
// I hope you have some code below this line to actually display the returned data

如果您对此查询有任何其他问题,它们与您发布的代码无关。检查拼写错误、正确的凭据、正确保存的文件和实际数据。

于 2013-01-26T07:27:09.897 回答