Mavrik347 Posted October 12, 2010 Share Posted October 12, 2010 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? :/ Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/ Share on other sites More sharing options...
BlueSkyIS Posted October 12, 2010 Share Posted October 12, 2010 echo the value of $c->db_name to see what it is. Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121552 Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2010 Share Posted October 12, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121554 Share on other sites More sharing options...
Mavrik347 Posted October 12, 2010 Author Share Posted October 12, 2010 @ BlueSkyIS db_name: sever_ts3 Which is correct :/ @ 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) Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121557 Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2010 Share Posted October 12, 2010 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.) Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121567 Share on other sites More sharing options...
Mavrik347 Posted October 12, 2010 Author Share Posted October 12, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121574 Share on other sites More sharing options...
Mavrik347 Posted October 13, 2010 Author Share Posted October 13, 2010 Is everyone else stumped? :/ No theories or ideas? I'm at a loss. Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121832 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2010 Share Posted October 13, 2010 If you use mysql_error() in your die() statement, it will tell you why the particular mysql_ statement failed. Quote Link to comment https://forums.phpfreaks.com/topic/215723-cannot-select-database/#findComment-1121850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.