ballhogjoni Posted May 8, 2007 Share Posted May 8, 2007 How would you include the db connection info into another file? example: <?php $username="xxxx"; $password="xxxx"; $database="xxxx"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); mysql_close(); ?> <?php include("xxxx.com/tests/xxxxx/config.php"); // the rest of the code ?> for some reason this is not working dfor me. where am i going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/ Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 First off don't just supress errors with the @ sign, not very good especially when debugging. Second localhost needs to be surrounded by quotes IE: <?php mysql_connect('localhost',$username,$password); Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248490 Share on other sites More sharing options...
Caesar Posted May 8, 2007 Share Posted May 8, 2007 Third, it's better practice to use a relative path when calling up that 'config.php' file :-P Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248494 Share on other sites More sharing options...
ballhogjoni Posted May 8, 2007 Author Share Posted May 8, 2007 Ok, Thanks. How do i unspress the errors? and any other ideas because just adding the quotes dint work. Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248497 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 Remove the @ sign from the front of them. Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248504 Share on other sites More sharing options...
ballhogjoni Posted May 8, 2007 Author Share Posted May 8, 2007 I appreciate your input, but it still dint do anything. Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248511 Share on other sites More sharing options...
papaface Posted May 8, 2007 Share Posted May 8, 2007 Remove mysql_close(); You are closing the connection. Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248514 Share on other sites More sharing options...
ballhogjoni Posted May 8, 2007 Author Share Posted May 8, 2007 Third, it's better practice to use a relative path when calling up that 'config.php' file :-P This is what made it work. Thank you all for you help. Quote Link to comment https://forums.phpfreaks.com/topic/50559-solved-include-db-connection/#findComment-248524 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.