我现在使用MAMP几个月,但今天我安装了AMPPS。
我将使用数据库,但它不起作用。 我收到以下错误:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /Applications/AMPPS/www/functions.php:13 Stack trace: #0 /Applications/AMPPS/www/functions.php(13): PDO->__construct('mysql:host=loca...', 'root', 'usbw') #1 /Applications/AMPPS/www/functions.php(22): dbConn() #2 /Applications/AMPPS/www/test.php(18): imageDropdown('s') #3 {main} thrown in /Applications/AMPPS/www/functions.php on line 13
代码:
// database connection
function dbConn() {
$username = "root";
$password = "usbw";
$dbh = new PDO(
'mysql:host=localhost; port=3306; dbname=webshop',
$username,
$password
);
return $dbh;
}
// dropdown met afbeeldingen
function imageDropdown($zoek) {
$dbh = dbConn();
$sth = $dbh -> prepare("
SELECT afbeelding
FROM Afbeelding
WHERE afbeelding LIKE '%:zoek%'
ORDER BY afbeelding
");
$sth -> bindValue(":zoek", $zoek, PDO::PARAM_STR);
$sth -> execute();
$result = $sth -> fetchAll(PDO::FETCH_ASSOC);
print("<pre>");
print_r($result);
print("</pre>");
}
&GT;
(的functions.php)
<?php
include "functions.php";
imageDropdown("s");
?>
(test.php的)
缺少驱动程序,但如何安装?
我在Mac上。
答案 0 :(得分:1)
在用户界面 - PHP选项卡 - php扩展。检查是否启用了必需的扩展。像pdo_mysql和pdo