I have Xampp
on Windows 10 and apached started on it. My project is did in Laravel 8
. I want to use PDO
in controller:
$pdo = DB::connection('mysqlPDO')->getPdo();
$stmt = $pdo->prepare("SELECT * FROM `form_data` WHERE `id`=:id LIMIT 1");
$stmt->bindValue(':id', 1, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll();
$stmt->closeCursor();
unset($stmt);
When I run above code I get error:
Class 'App\Console\Commands\PDO' not found
at C:\xampp\htdocs\crm-api\app\Console\Commands\Import.php:58
54▕
55▕ $pdo = DB::connection('mysqlPDO')->getPdo();
In Xampp
in php.ini I have extensions:
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
When I uncomment for example pdo_oci I get error: Xampp start error
I downloaded php_pdo.dll
into xampp/php/ext
folder and added extension=pdo
to php.ini
but still have the same bug
first of all, if you do not use multiple database connections, you should use (you can learn more here)
$pdo = DB::connection()->getPdo();
secondly, check your database information in .env file, can you run migrations?
after that, if you can not enable any of extensions, you should check XAMPP's directory, then php/ext folder and see if there is .dll file for your extension, if not, you should install them manually.
P.S.: also please check if you have uncommented following extension and restart apache server.
extension=pdo