Jump to content

Cannot select database


Mavrik347

Recommended Posts

Hi guys, it's me Captain Failure, back with more antics. :)

 

I can't get this to link to the database and was wondering if anyone could help :/

The main code is the second block below but I have posted some of the config file also.

 

Config.php

public $db_host = 'localhost';
public $db_user = 'user';
public $db_pass = 'pass';
public $db_name = 'db';

 

Main page

require_once('config.php');
$c = new Config;

$query = "DELETE FROM tsclient WHERE id = '".$uid."';";
$db_connection = mysql_connect($c->db_host,$c->db_user,$c->db_pass);
if (!$db_connection) {
	die($errmsg['ERR_MYSQL']);
}
$db_selection = mysql_select_db($c->db_name,$db_connection);
if (!$db_selected) {
	die($l->errmsg['ERR_DBFAIL']);
}
mysql_query($query,$db_selection);
mysql_close($db_connection);

I keep hitting

die($l->errmsg['ERR_DBFAIL']);

but can't work out why... The use has All Privileges in that database and the user/pass details must be correct because it is actually connecting and not giving out [ph]die($errmsg['ERR_MYSQL']);[/code]

 

 

Can anyone help? :/

Link to comment
Share on other sites

Your code is using two different variables - $db_selection and $db_selected.

 

Please develop and debug code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. You will save a ton of time with these simple mistakes.

Link to comment
Share on other sites

@ BlueSkyIS

db_name: sever_ts3

 

Which is correct :/

ts3hx.jpg

 

@ PFMaBiSmAd

omg... how could I be so stupid.? Thanks, is that a server option or something you can do client side? I'm using Dreamweaver CS5.

 

 

The code is now:

$query = "DELETE FROM tsclient WHERE id = '".$uid."';";
$db_connection = mysql_connect($c->db_host,$c->db_user,$c->db_pass);
if (!$db_connection) {
	die($errmsg['ERR_MYSQL']);
}	
$db_selection = mysql_select_db($c->db_name,$db_connection);
if (!$db_selection) {
	echo "db_name: $c->db_name";
	die($l->errmsg['ERR_DBFAIL']);
}
mysql_query($query,$db_selection);
mysql_close($db_connection);

But it is still doing it :/

 

http://www.sev3rance.com/ts3/cron.php (May take a minute to load)

Link to comment
Share on other sites

You are also using $db_selection in the mysql_query() statement. It should be $db_connection.

 

The two settings I mentioned should be set in your master php.ini so that fatal parse errors will also be reported and displayed. Stop and start your web server to get any changes made to the master php.ini to take effect and confirm that the settings actually got changed using a phpinfo(); statement (in case the php.ini that you changed is not the one that php is using.)

Link to comment
Share on other sites

Thanks, I'll take a look into that.

 

I've changed it to $db_connection but it still fails the step ahead :/ I'm totally stumped.

$query = "DELETE FROM tsclient WHERE id = '".$uid."';";
$db_connection = mysql_connect($c->db_host,$c->db_user,$c->db_pass);
if (!$db_connection) {
	die($errmsg['ERR_MYSQL']);
}
$db_selection = mysql_select_db($c->db_name,$db_connection);
if (!$db_selection) {
	echo "db_name: $c->db_name";
	die($l->errmsg['ERR_DBFAIL']);
}
mysql_query($query,$db_connection);
mysql_close($db_connection);

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.