Jump to content

MySQL connection details link


psychowolvesbane

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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)

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.