₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,969 members, 8,448,033 topics. Date: Sunday, 19 July 2026 at 02:58 PM

Toggle theme

PHP Can't Connect With PDO - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPHP Can't Connect With PDO (1124 Views)

1 Reply (Go Down)

PHP Can't Connect With PDO by Thirdwrist(op): 2:55pm On May 18, 2017
I have two files config.php and connection.php and I have been trying to establish a connection to no avail. here are the codes

the error says:
"'task', 'username'=> 'root', 'password'=> '', 'connection'=> 'mysql:host=localhost' ]; NULL invalid data source name".
 config.php
<?php

class connection
{
public static function make($config)
{

try
{
return new PDO(
$config['connection'].';dbname='.$config['name'],
$config['username'],
$config['password']
);
}

catch(PDOException $e)
{
die($e->getMessage());
}

}
}


//$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);





connection.php

<?php

class connection
{
public static function make($config)
{

try
{
return new PDO(
$config['connection'].';dbname='.$config['name'],
$config['username'],
$config['password']
);
}

catch(PDOException $e)
{
die($e->getMessage());
}

}
}


//$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
Re: PHP Can't Connect With PDO by Thirdwrist(op): 3:05pm On May 18, 2017
petjoe9:
Weather is the ability of fully experienced life, Thank God almighty.
Try use your sense once in a while. Its good for you.
Re: PHP Can't Connect With PDO by webdeveloperqx: 9:21am On May 19, 2017
Thirdwrist:
I have two files config.php and connection.php and I have been trying to establish a connection to no avail. here are the codes

the error says:
"'task', 'username'=> 'root', 'password'=> '', 'connection'=> 'mysql:host=localhost' ]; NULL invalid data source name".
Your (DSN) data source name is invalid . simply use a valid one .
1 Reply

Help Me With PDOHow Do I Retrieve Data With Apostrophe From Mysql Using PDOXAMPP Mysql ERROR: PDO Driver Not Found234

Cali_codersHow Do You Make Online Payments To Foreign Vendors ?Learn Programming