DB Connection script failing, php

I have index.php that requires config.php, and sql.php.

Config.php has the database credentials and sql.php has the following code
function dbconnect()
{
 global $db_connect_info;
	$errormessage = "<center><h2>Sorry.</h2><br />Service unavailable, please contact to the administrator.</center>";
	$db = @mysql_connect($db_connect_info["dbhost"], $db_connect_info["dbuser"], $db_connect_info["dbpassword"]) or die ($errormessage);
	@mysql_select_db($db_connect_info["dbname"],$db) or die ($errormessage);
}

Open in new window


This is an older script that im trying to use. Not sure if it's outdated or not. I did test my credentials to the database were correct by using a simple script.

<?php
mysql_connect('db_host', 'myuser', 'password') or die('Could not connect the database : Username or password incorrect');
mysql_select_db('esudmanager') or die ('No database found');
echo 'Database Connected successfully';
?>

Open in new window

cnl83Asked:
Who is Participating?
 
Nathan RileyFounderCommented:
Your using old mysql commands, I would update to mysqli, check the below example of how to connect and query.

$db = new mysqli("localhost", "user", "pass", "database");
$sql="select * from table";
$db->query($sql);
0
 
Dave BaldwinFixer of ProblemsCommented:
Using '@' in front of functions only suppresses the reporting of errors, it does not make the errors go away.  I never do that.  In addition, nothing is returned from your function which means in effect it does nothing.  And Nathan is correct about using the old mysql functions, they are going away.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.