psychowolvesbane Posted January 3, 2008 Share Posted January 3, 2008 Hi I was wondering how I would go about using variables that contain my login information for MySQL without listing them on the current script, but on a separate page in a more secure folder. So the connection code is $conn = mysql_connect($host,$Username,$Password); //Select the MySQL database $db = mysql_select_db($Dbname, $conn); and to link the current scripted page (index.php) to the one that contains the variables and their values (connection_details.inc) ? I tried using a <?php require('connection_details.inc')?> and place that in the <body> tags but if that is correct does it need to go in the <head> tags? Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2008 Share Posted January 3, 2008 Name your include file with a .php ending so that it will be parsed by php if anyone should browse to it and they won't be able to see the contents of the file. When it ends in .inc, if someone should guess or otherwise find out what the file name is, they can just browse to it and see the php code and data in it. Php code is parsed on the web server when the page is requested. The head and body of a html document does not really have any meaning at that point in time. Your php code is basically placed in the order and location in the page it is needed in to logically produce the resultant overall web page. Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429714 Share on other sites More sharing options...
psychowolvesbane Posted January 3, 2008 Author Share Posted January 3, 2008 So would the link be <?php require('connect_details.php.inc')?> ? Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429721 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 <?php require('connect_details.php')?> Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429725 Share on other sites More sharing options...
psychowolvesbane Posted January 3, 2008 Author Share Posted January 3, 2008 I'm still not getting it to work. I've got this as my connection queries: $conn = mysql_connect('$Host:3306','$Username','$Password'); //Select the MySQL database $db = mysql_select_db('$Dbname', $conn); My file name for the connection is: connect_details.php.inc and my link is: <?php require('connect_details.php')?> I'm getting the error: Unknown MySQL Server Host '$Host' (1) on line 26 which is: $conn = mysql_connect('$Host:3306','$Username','$Password'); Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429733 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Need double quotes for variables $conn = mysql_connect("$Host:3306","$Username","$Password"); Remove the :3306 too and put it in the $Host variable if it's even required. Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429736 Share on other sites More sharing options...
psychowolvesbane Posted January 3, 2008 Author Share Posted January 3, 2008 Still not working: $conn = mysql_connect("$Host","$Username","$Password") or die(mysql_error()); $db = mysql_select_db("$Dbname", $conn); $Host now has the port number in it, it is required. Error is: Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/psychowolvesbane.freehostia.com/menu.inc on line 26 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429740 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 What error. Make sure your variables use a Capital first letter in your connect_details.php too. Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429743 Share on other sites More sharing options...
psychowolvesbane Posted January 3, 2008 Author Share Posted January 3, 2008 Sorry I posted the error in an edit. Also yes my variables are exactly the same in both cases. Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429745 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 That's something you're going to have to show to your Host provider I think. The data is now being read correctly and is being passed to your connect string. Quote Link to comment https://forums.phpfreaks.com/topic/84367-mysql-connection-details-link/#findComment-429747 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.