Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,398 members, 7,819,419 topics. Date: Monday, 06 May 2024 at 03:58 PM

PHP Can't Connect With PDO - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / PHP Can't Connect With PDO (958 Views)

Help Me With PDO / How Do I Retrieve Data With Apostrophe From Mysql Using PDO / XAMPP Mysql ERROR: PDO Driver Not Found (2) (3) (4)

(1) (Reply) (Go Down)

PHP Can't Connect With PDO by Thirdwrist(m): 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(m): 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 Like

(1) (Reply)

Make Money Blogging / Learn At All Tech Systems / How To Learn Programming(Beginner.)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.