Eroare: PDOException invalid data source name
Scris: Mie Oct 07, 2015
Salut
Am la un script aceste setari in config.php:
Si functia pt conectare la mysql cu pdo:
Imi da eroarea :
Am creat baze de date noi, tot degeaba.
Am la un script aceste setari in config.php:
Cod: Selectaţi tot
// Main Website configuration:
$_CONFIG['site_name'] = 'www.site - Stick-ul Tau Online'; // Site Name
$_CONFIG['site_url'] = 'www.site'; // Site URL (notice: no tralining slash in the end!)
$_CONFIG['site_path'] = 'www.site'; // Website PATH (notice: no tralining slash in the end!)
$_CONFIG['admin_mail'] = 'dancrisro@yahoo.com'; // Mail used in contact us page
$_CONFIG['database'] = 'baza-de-date'; // Database file!
$_CONFIG['mysql'] = 'mysql:host=localhost;dbname=xxxxxxx'; // mysql pdo connect string change host value and dbname value!
$_CONFIG['username'] = 'Username '; // mysql databasse username
$_CONFIG['password'] = 'parola'; // mysql user password
$_CONFIG['usemysql'] = true; // use mysql? False = use pdo sqlite.
Cod: Selectaţi tot
// custom database function easy changeable to any pdo supported databases.
function mycustomdb() {
global $_CONFIG;
if ($_CONFIG['usemysql']) {
// Conect to an mysql database (need to install it first from phpmyadmin...)
$custom_db = new PDO($_CONFIG['mysql'], $_CONFIG['username'], $_CONFIG['password']);
} else {
// Create (connect to) SQLite database in file
$custom_db = new PDO('sqlite:'.$_CONFIG['database'].'');
}
// Set errormode to exceptions
$custom_db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
return $custom_db;
}
Cod: Selectaţi tot
Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in /home/rohostin/public_html/config.php:62 Stack trace: #0 /home/rohostin/public_html/config.php(62): PDO->__construct('', 'rohostin_rohost...', 'rohostingro') #1 /home/rohostin/public_html/page.php(111): mycustomdb() #2 {main} thrown in /home/rohostin/public_html/config.php on line 62