1

I have been doing some searches on google and realize i have to put mysql database username and password in a file using a .htaccess: The problem is how do i do that? some say place it in external folder not in web root. How can I also request the details i sent to database on another page, (Like show it on another page) maybe in a div. (Dunno).

Please I need a comprehensive guide. Most importantly secure connection to db. A php script that sends the information to db. Request the info back and showed in a div. Thanks in advance

flag

1 Answer

0

You can create an include file to store MySQL server address, username, password etc and place it outside of your website root directory. In this case it won't be downloadable via HTTP.

Typical directory structure:

inc
httpdocs
  myapp
httpsdocs
...

Include file (dbcommon.php) goes to inc directory, your app is located in httpdocs/myapp directory.

In your application you can use the following:

include("../../inc/dbcommon.php");
$conn = mysql_connect($host,$user,$pwd);
if (!$conn || !mysql_select_db($sys_dbname,$conn)) 
  {
    trigger_error(mysql_error(), E_USER_ERROR);
  }

Sample content of dbcommon.php file:

<?php

$host="localhost";
$user="root";
$pwd="rootpwd";
$port=3306;
$sys_dbname="mydatabase";

?>
link|flag

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.