Page 1 of 1

problem connecting to database :: Warning: mysql_connect() [

Posted: Tue Jan 13, 2009 10:51 pm
by darren713
Hello all
I have a problem connecting my msql db to the server. the db i use and have created works completely fine in my localhost however when i upload the files with the include to connection.php the realtime live sie comes up with

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in /includes/connection.php on line 4
Database connection failed: Access denied for user 'root'@'localhost' (using password: YES)

Here is what i have tried so far.
gone into mysql console and ran this line

Code: Select all

SET PASSWORD FOR
'root'@'localhost' = OLD_PASSWORD('new_pass');
Also i tried the UPDATE and FLUSH PRIVALIGES cmd's to no joy

my constants.php file is correct to the mysql cmd like so

Code: Select all

<?php
 
 
define("DB_SERVER","localhost");
define("DB_USER", "root");
define("DB_PASS", "pxxxxxxx");
define("DB_NAME", "my-db");
 
?>
my connection.php looks like this

Code: Select all

<?php
require("constants.php");
//1. create a connection
    $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); 
    if (!$connection) {
        die("Database connection failed: " . mysql_error());
    }
 
    // 2. Select a database to use 
    $db_select = mysql_select_db(DB_NAME,$connection);
    if (!$db_select) {
        die("Database selection failed: " . mysql_error());
    }
?>
I have spoke to my server administrator and they say its completely fine using a mysql db from another server as such so how or where am i going wrong because i am banging my head against the wall.

p.s the testing server url prefix is set to my local localhost

Re: problem connecting to database :: Warning: mysql_connect() [

Posted: Sat Jun 06, 2009 11:05 am
by akuji36
Its not a good idea to have server name set to root.

Best change it to something else:

these files should help.

for your connection:

Code: Select all

require("constants.php");
 
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
    die("Database connection failed: " . mysql_error());
}
 
// 2. Select a database to use 
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
    die("Database selection failed: " . mysql_error());
}
 
constants

Code: Select all

require("constants.php");
 
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
    die("Database connection failed: " . mysql_error());
}
 
// 2. Select a database to use 
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
    die("Database selection failed: " . mysql_error());
}