PHP namespace PDO not found

后端 未结 2 1350
青春惊慌失措
青春惊慌失措 2020-12-31 06:25

I\'m facing an issue I unfortunatly could not resolve so far. I created a database class into app/db/mysql/database.php with the following content

相关标签:
2条回答
  • 2020-12-31 06:35

    If you use PDO then you should add the line use PDO in the file where you are going to use the class PDO Ford example in file where you create object PDO and in each the file of model.

    0 讨论(0)
  • 2020-12-31 06:56

    Question was already edited, but for people who are just heading straight over to the answers, here it is..

    You should be using correct namespaces for the objects in your methods, either "use" them or prefix them with the root namespace;

    <?php
    //... namespace etc...
    
    use \PDO;
    
    self::$connection = new PDO("mysql:host=$host;dbname=$base", $user, $pass);
    

    or simply;

    self::$connection = new \PDO("mysql:host=$host;dbname=$base", $user, $pass);
    
    0 讨论(0)
提交回复
热议问题