我使用pdo方法进行php搜索。但结果在我的应用程序中没有正确显示。我的语言是波斯语,我认为理由是utf8,应该在我的pdo中。有人可以帮忙吗?
if (isset($_POST['searchQuery'])) {
require_once('config.inc.php');
$search_query = $_POST['searchQuery'];
$sql = 'SELECT * from nmh where MATCH(company,name,family) AGAINST(:search_query)';
$statement = $connection->prepare($sql);
$statement->bindParam(':search_query', $search_query, PDO::PARAM_STR);
$statement->execute();
if ($statement->rowCount()) {
$row_all = $statement->fetchall(PDO::FETCH_ASSOC);
header('Content-type: application/json');
echo json_encode($row_all);
} elseif (!$statement->rowCount()) {
echo "no rows";
}
}
答案 0 :(得分:0)
像这样设置连接
$connection = new PDO('mysql:host=localhost;dbname=DBNAME;charset=utf8', 'root', 'root');
$connection->query("SET CHARACTER SET utf8");