Próbowałem dodać set names, ale wtedy skrypt przestaje działać. W innych miejscach set names dodawałem bez problemu i działało.
<?php
// We will use PDO to execute database stuff.
// This will return the connection to the database and set the parameter
// to tell PDO to raise errors when something bad happens
function getDbConnection() {
$db = new PDO(DB_DRIVER . ":dbname=" . DB_DATABASE . ";host=" . DB_SERVER . ";charset=utf8", DB_USER, DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
}
// This is the 'search' function that will return all possible rows starting with the keyword sent by the user
function serachForKeyword($keyword) {
$db = getDbConnection();
$stmt = $db->prepare("SELECT DISTINCT kupujacy_nazwa as nazwa FROM `protokol` WHERE kupujacy_nazwa LIKE ? ORDER BY kupujacy_nazwa");
$keyword = $keyword . '%';
$stmt->bindParam(1, $keyword, PDO::PARAM_STR, 100);
$isQueryOk = $stmt->execute();
if ($isQueryOk) {
$results = $stmt->fetchAll(PDO::FETCH_COLUMN);
} else {
}
$db = null;
return $results;
}