我面临一个问题,我不幸无法解决.我创建了一个数据库类到app / db /
mysql / database.PHP,具有以下内容:
原文链接:https://www.f2er.com/php/139919.html<?PHP namespace App\Database; use Symfony\Component\Yaml\Yaml; class Database{ private static $connection = null; private function __construct( $host,$base,$user,$pass ){ try{ self::$connection = new PDO("MysqL:host=$host;dbname=$base",$pass); }catch(PDOException $e){ die($e->getMessage()); } } public static function get(){ if( self::$connection !== null ){ return self::$connection; } $yaml = Yaml::parse(file_get_contents(realpath('./app') . '/database.yml')); self::$connection = new Database( $yaml['host'],$yaml['base'],$yaml['user'],$yaml['pass'] ); } }
使用作曲家,我自动加载这个类:
{ "autoload" : { "classmap" : [ "app/libraries","app/db" ] } }
其中生成一个autoload_classmap.PHP,如:
return array( 'App\\Database\\Database' => $baseDir . '/app/db/MysqL/database.PHP','App\\Libraries\\Parser' => $baseDir . '/app/libraries/Parser.PHP',);
现在,一切正常,我总是会遇到与PDO有关的错误:
Fatal error: Class 'App\Database\PDO' not found in /var/www/my_application/app/db/MysqL/database.PHP on line 24