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..  ::)

Link to comment
Share on other sites

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"]
);
?>

 

 

 

Link to comment
Share on other sites

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

 

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.