...

View Full Version : Connect to MySql Database



robbiez
01-17-2010, 09:46 AM
Hi
I am hoping someone can point me in the right direction.
I have changed my hosting package from a shared package to dedicated server and have been trying to reinstall the software that was developed for me using a new database.
Previously the code to connect was

define( "DB_DSN", "mysql://dbo*****:PASSWORD@db****.oneandone.co.uk/db******");
I changed the code to:

define( "DB_DSN", "mysql://dbo*****:PASSWORD@localhost:/tmp/mysql5.sock/db******");

replacing the db****.oneandone.co.uk with localhost:/tmp/mysql5.sock as the new database is hosted on my dedicated server. Obviously I changed all the details as well. However it will not connect to the new database.

I understand the define("DB_DSN string is causing errors and it has been recommended I use

define('DB_DSN', 'mysql/localhost:/tmp/mysql5.sock/db****');
define('DB_USER', 'dbo**** ');
define('DB_PASS', 'PASSWORD');

but that also creates an error and somehting needs to changed with this part of the code as well - this is what I am stuck on:

function &db_connect() {
$db_options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::connect(DB_DSN, $db_options);
db_show_error($db);

return $db;
}
// Connect to given dsn
function &db_connectByDsn($dsn) {
$db_options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::connect($dsn, $db_options);
db_show_error($db);

return $db;
}

Thanks for any help anyone can offer.
Robbiez

Dormilich
01-17-2010, 01:17 PM
judging from the DB docs, your DSN is wrong. if you have a common acces type, it should look like mysql://user:pass@localhost/database. check also the given examples, e.g. if you connect through a unix socket.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum