0

I have php search using pdo method. But results doesn't show correctly in my application. My language is Persian and i think reason is utf8 and that should be in my pdo. Anyone can help?

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";
    }
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

0

setup the connection like this

$connection = new PDO('mysql:host=localhost;dbname=DBNAME;charset=utf8', 'root', 'root');
$connection->query("SET CHARACTER SET utf8");
Ali Faris
  • 17,754
  • 10
  • 45
  • 70