PDO - Class Not Found

1

What's happening

I created a static method to return the connection so that I can use it in DAO, but doing so gives Class Not Found PDO .

OtherProjects

Thefirstthingthatmanypeoplewillthinkis,"The extension is not activated." Sirs, the extensions are properly activated and have already been used in other projects. I have here 2 other projects with the PDO, but this time I tried to use Object Orientation in the best possible way, to make the code more clean.

OBS:

If anyone has any suggestions for leaving some class more 'beautiful', I will be open to modifications.

Active PDO

My Code

Class EntityDAO

<?php

namespace Presto\model;
use Presto\model\ConnectionFactory as ConnectionFactory ;

class EntidadeDAO {
    private $connection = null;

    public function __construct() {
        self::$connection = ConnectionFactory::getConnection();
    }
} 

Class ConnectionFactory

<?php
namespace Presto\model;

class ConnectionFactory {

public static function getConnection() {
    $connection = null;
    $config = self::configureConnection();

    try {
        self::$conection = new PDO($config['databaseType'].':host='.$config['hostname'].';dbname='.$config['database'],$config['username'],$config['password']);
    }catch (PDOException $e) {
        echo $e->getMessage();
    }

    return self::$connection;
}

public static function configureConnection() {
    $config = array();

    $config['databaseType'] = 'pgsql';
    $config['hostname'] = '127.0.0.1';
    $config['database'] = 'minhaDatabase';
    $config['username'] = 'root';
    $config['password'] = 'password';

    return $config;
}
} 
    
asked by anonymous 29.05.2015 / 17:13

1 answer

3

Learn to interpret the \ Presto \ model \ PDO error not found, when working with namespace, is each backslash a correct directory?

To use the PDO lib or native libraries that need to be instantiated, use the backslash before it points to the root, ie the native PHP libraries.

Example: \ PDO

public static function getConnection() {
    $connection = null;
    $config = self::configureConnection();

    try {
        self::$conection = new \PDO($config['databaseType'].':host='.$config['hostname'].';dbname='.$config['database'],$config['username'],$config['password']);
    }catch (\PDOException $e) {
        echo $e->getMessage();
    }

    return self::$connection;
}
    
29.05.2015 / 18:16