Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14120 reviews 1680 hosting providers

Questions & Answers

Creating Config file to edit MYSQL

Feb 12, 2013 by rooby
Hi..

I want  to create a config file to be able to edit MYSQL connection information to my online database. How can I do this? Please advice?
Thanks

1 Answer

0 votes
Feb 12, 2013 by tareq101
Create a file called config.php . This file should contain all define variables, and then you should do the actual connection in your main file. something like this:
config.php
<?php

  $dbHost = 'yourlocalhost';
  $dbUser = 'youruser';
  $dbPass = 'yourpass';
  $dbName = 'yourdbname';

?>
main.php
<?php

  require('config.php');
  if (!$con = mysql_connect($dbHost, $dbUser, $dbPass)) {
    die('Cannnot connect: ' . mysql_error());
  }
  if (!mysql_select_db($dbName, $con)) {
    die(‘Cannot select database');
  }

  // the rest of your code

?>