我使用 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>");
}
?>
(函数.php)
<?php
include "functions.php";
imageDropdown("s");
?>
(test.php)
缺少驱动程序,但如何安装?
我在 Mac 上。