Connecting to MySQL in x10Hosting

iShout

New Member
Messages
2
Reaction score
0
Points
0
Hey I'm trying to connect to the MySQL server using a user I created (in the PHP code I provided the exact username and password) yet it keeps writing that the access was denied.
What is the exact host for the server in x10hosting?
sorry if this is the wrong forum.
thx
 

EliteACE

New Member
Messages
9
Reaction score
0
Points
0
PHP:
<?php
/* Connect to Database */
$link = mysql_connect( "localhost", "username", "password" );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}

mysql_select_db( "database_name", $link )
    or die ( "Couldn't connect to database: ".mysql_error() );
?>
Note that with your database's and username, they have a prefix. That is what you may have missed. The prefix is your subdomain name. So.... subdomain_username and subdomain_databasename
 
Last edited:

burner35

New Member
Messages
127
Reaction score
0
Points
0
Are you also changing "localhost" to your domain/subdomain? I'm not sure if EliteACE has said the same thing. ;)
 

iShout

New Member
Messages
2
Reaction score
0
Points
0
I tried both with and without prefixes, and I used my subdomain ishout.exofire.net as the host.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Are you putting your cpanel username(not sure where you got subdomain from) before the username and database name.
eg:
PHP:
<?php
/* Declare Variables */
$host = 'localhost'; // will always be this
$username = 'user'; // database username
$password = '123'; // database password
$dbname = 'testdb'; // database name
$root = 'joeblob'; // cpanel username

/* Connect to Database */
if($root) { $username = $root.'_'.$username; }
$link = mysql_connect($host, $username, $password);
if(!$link)
{
 die("Couldn't connect to MySQL: ".mysql_error());
}
else
{
 if($root) { $dbname = $root.'_'.$dbname ; }
 mysql_select_db( $dbname, $link ) 
    or die ( "Couldn't connect to database: ".mysql_error() );
}
?>
 
Top