Jump to content

Help with Connecting to DB


Dethman

Recommended Posts

Heres the Code that I am using and the DB info is under it

<?php
session_start() or DIE("A session could not be created! Please Contact the administrator");;
mysql_connect('localhost', '10352_reality', '123456') or DIE("UNABLE TO CONNECT TO DATABASE! Please Contact the administrator");
mysql_select_db('10352_reality') or DIE("UNABLE TO SELECT THE DATABASE! Please Contact the administrator");
?>

 

Now heres the DB info:

 

Database Server Name:  	mysql
Database: 	10352_reality
Username: 	10352_reality
Password: 	123456

 

But I still get the "CANNOT CONNECT TO THE DATABASE" Error

Cant Figure  it out could it be the "Localhost" Thing Is there something else I can put there?

Link to comment
Share on other sites

You shouldn't die a custom error, but you should die a mysql error.

This is how a connection should be made

 

<?php
error_reporting(E_ALL);
$con = mysql_connect('server_name', 'db_username', 'db_password') or die('MySQL Error: ' . mysql_error());

if($con)
  mysql_select_db('db_name') 
    or die('MySQL Error: ' . mysql_error());

?>

 

Using mysql_error() will explicity give you the specific error as to why PHP can't make a connection to the database.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.