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
https://forums.phpfreaks.com/topic/108974-help-with-connecting-to-db/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.