PDO CONNECTION
Подключение и управление Подключение ¶
Connections are established by creating instances of the PDO base class. It doesn't matter which driver you want to use; you always use the PDO class name. The constructor accepts parameters for specifying the database source (known as the DSN) and optionally for the username and password (if any).
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); <<== This is the PDO DATABASE OBJECT
function getSlug($param)
{
$sth = $dbh->prepare("SELECT * FROM articles WHERE slug = ?"); <<== First you need to prepare it
$sth->execute(array($param)); <<== Then execute it using params
$result = $sth->fetchAll(PDO::FETCH_ASSOC); <<== Then USe PDO Constant to get Associative array
return $result; <<<== Then return it
}
?>
Вы читали документ PDO? –
Сначала вам нужно «подготовить» запрос. Затем «выполнить» это с помощью PARAMS.Тогда вы можете вернуть результат с помощью 'PDO: FETCH_ASSOC' Constant – underscore