我有这个简单的代码来根据相关性制作搜索结果:
$stmt = $db->query('SELECT * FROM `apps` WHERE MATCH(appName, appSeller) AGAINST("angry")');
$appCount = $stmt->rowCount();
echo $appCount;
它没有显示任何结果!
先谢谢你的帮助, 马塞尔
答案 0 :(得分:3)
Stackoverflow的可用性低于零 因为没有办法让所有人在PDO标签下发布问题显示半屏横幅:
因为在没有错误消息的情况下询问是没有意义的,但错误消息很可能会使问题变得不必要。
$dsn = 'mysql:host=localhost;dbname=test;charset=utf8';
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
);
$pdo = new PDO($dsn,'root','', $opt);
答案 1 :(得分:1)
尝试
'SELECT * FROM `apps` WHERE MATCH(appName, appSeller) AGAINST("angry")'
在phpmyadmin中查看它是否真的返回任何内容。
答案 2 :(得分:0)
试试这个
<?php
// Connection data (server_address, database, name, poassword)
$hostdb = 'localhost';
$namedb = 'tests';
$userdb = 'username';
$passdb = 'password';
try {
// Connect and create the PDO object
$db = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$db->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// Define and perform the SQL SELECT query
$sql = "SELECT * FROM `apps` WHERE MATCH(appName, appSeller) AGAINST("angry")";
$stmt = $db->query($sql);
// If the SQL query is succesfully performed ($stmt not false)
if($stmt !== false) {
$cols = $stmt->columnCount(); // Number of returned columns
echo 'Number of returned columns: '. $cols. '<br />';
// Parse the result set
foreach($stmt as $row) {
echo $row['id']. ' - '. $row['name']. ' - '. $row['category']. ' - '. $row['link']. '<br />';
}
}
$db = null; // Disconnect
}
print_r($sth->errorInfo());
}
?>
答案 3 :(得分:-1)
将您的代码包含在try和catch块中,然后您应该知道SQL语法出错的地方:
try {
// your code
} catch ( PDOException £e ) {
echo $e->getMessage();
exit();
}