Jump to content

[SOLVED] How do I make a professional (config.php) file?


s.mujtaba

Recommended Posts

Hi everyone

I want to a config.php file to make connection with database

but when make it, It's like this:

<?php
mysql_connect(
/*dbhost*/ "localhost",
/*dbuser*/ "root",
/*dbpass*/ ""
);
mysql_select_db(
/*dbname*/ "data"
);
?>

 

But I don't want it like that, I want it like this:

<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "data";
?>

 

Please help me to make it professional..  ::)

please help me fast  :'(  :-[  :(

 

It certainly was not professional of you :P

 

How about this

 

<?php
$config = array(
  "dbhost" => "localhost",
  "dbuser" => "root",
  "dbpass" => "",
  "dbname" => "data"
);
?>

 

And then you use it in your other files using require

 

For example

<?php
require_once("config.php");

mysql_connect(
  $config["dbhost"],
  $config["dbuser"],
  $config["dbpass"] 
);

mysql_select_db(
  $config["dbname"]
);
?>

 

 

 

My... and just how difficult would that be?

 

<?php
  $dbhost = "localhost";
  $dbuser = "root";
  $dbpass = "";
  $dbname = "data";
?>

 

<?php
require_once("config.php");

mysql_connect(
  $dbhost,
  $dbuser,
  $dbpass 
);

mysql_select_db(
  $dbname
);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.