So i always get a pdo exception when i try to create my db in the constructor of my Mapper class. on this line:
$this->db = new PDO($dsn, $db_config['username'], $db_config['password']);
this is my dsn creation:
$db_config = array(
'driver' => 'pgsql',
'username' => $dbUser,
'password' => $dbPassword,
'schema' => 'r0628740',
'dsn' => array(
'host' => 'gegevensbanken.khleuven.be',
'dbname' => '2TX31',
'port' => '51314',
)
);
and finaly my constructor:
public function __construct(){
global $db_config;
$dsn = $db_config['driver'] . ':';
foreach($db_config['dsn'] as $key => $value){
$dsn .= $key . '=' . $value . ';';
}
try{
$this->db = new PDO($dsn, $db_config['username'], $db_config['password']);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(($db_config['driver'] == 'pgsql') && isset($db_config['schema'])){
$this->db->query(sprintf("SET SEARCH_PATH TO %s"), $db_config['schema']);
}
}catch (PDOException $e){
var_dump($e->getLine());
error_log($e->getMessage());
}
}
The PHP contains a dll required by pgsql and pgsql_pdo driver libpq.dll... Add PHP binary path to system path or copy de DLL into Windows\\system32. On linux dependency are installed automatically.
I found article somewhere, works for me. Assuming you have installed PostgreSQL and your WAMP installation is on c:\\wamp
, you will need to copy:
c:\\wamp\\bin\\php\\php5.3.9\\libpq.dll
to c:\\wamp\\bin\\apache\\Apache2.2.11\\bin
.
Make sure you also have the following files:
C:\\wamp\\bin\\php\\php5.3.9\\ext\\php_pdo_pgsql.dll
and C:\\wamp\\bin\\php\\php5.3.9\\ext\\php_pgsql.dll
Also, make sure you have enabled the above 2 files as extensions, either via the WAMP menu (click on WAMP icon on taskbar: PHP > PHP extensions
, find the above 2 and 'check' them).
Please note that php5.3.9
and Apache2.2.11
refer to my specific PHP and Apache versions.
Adjust those to suit your installation.
Copying this libpq.dll from c:\\wamp\\bin\\php\\php5.3.9\\libpq.dll to c:\\wamp\\bin\\apache\\Apache2.2.11\\bin . has worked for me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.