Jump to content

[SOLVED] SQL LOGIN INFORMATION


DarkSuperHero

Recommended Posts

Would it be best to define any MySQL information in a CONSTANT or a variable ? Does it make much of a difference ?

<?php
define('HOST','localhost');
define('USER','root');
define('PASSWORD','');
define('DATABASE','test');

//OR.....

$host = 'localhost';
$user = 'root';
$password = '';
database = 'test';

 

by the way this is running on a local environment at the moment, but will be running on a production server in the future....

 

Link to comment
https://forums.phpfreaks.com/topic/139696-solved-sql-login-information/
Share on other sites

The fastest most efficient way to do this is to do this as a class constant:

 

<?php
class db
{
    Const db_host = "localhost";
    Const db_username = "username";
    Const db_password = "password";
}
?>

 

PHP handles class constants much better than global constants. To use this simply include the file and say:

 

<?php
mysql_connect(db::db_host, db::db_username, db::db_password) or die(mysql_error());
?>

Unless your worried about overwriting data using a standard variable is fine, Apart from that neither will perform any differently.

 

I use an array to hold all my config data like this

 

$CONFIG =  array(
host => 'localhost'
user => 'root'
pass => ''
database => 'test'
);

 

It's just down to preference

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.