Show DevBest [Php] Connect to MySQL! [Php]

Status
Not open for further replies.

DaLightz

See ya'll in the afterlife.
May 19, 2012
1,136
262
Hello Devbest! This MySQL connector was originaly for one of my old projects, but i figured i'd share it.

Config.php
PHP:
<?php
$_CONFIG['MySQL']['Hostname'] = 'localhost'; //host
$_CONFIG['MySQL']['Username'] = 'root'; //username
$_CONFIG['MySQL']['Password'] = 'fingerme'; //pass
$_CONFIG['MySQL']['Database'] = 'Mydb'; //db
?>


MySQL.php
PHP:
<?php //start the script.
//Gather connection details.
$_MySQL['Connection'] = mysql_connect($_CONFIG['MySQL']['Hostname'],$_CONFIG['MySQL'] ['Username'],$_CONFIG['MySQL']['Password']);
//Does it work?
if (!$_MySQL['Connection'])
  {
  die('<h1>ERROR!</h1><br><b> ' . mysql_error() . '</b>');
  }
//Select db.
mysql_select_db($_CONFIG['MySQL']['Database'], $_MySQL['Connection']);
 
?>

And there it is. Simple, and safe. Enjoy :}
 

GarettM

Posting Freak
Aug 5, 2010
833
136
For People Who Dont Know MYSQLi can be wrote Easily Too :)
I was Told That Mysqli is safer so here u go ( This works ive tested it )

Remember This is shit code JS this is the first step lol X) gotta love shit code

PHP:
<?php //start the script.
 
//Gather connection details.
 
$_MySQL['Connection'] = mysqli_connect($_CONFIG['MySQL']['Hostname'],$_CONFIG['MySQL'] ['Username'],$_CONFIG['MySQL']['Password'],$_CONFIG['MySQL']['Database']);
 
//Does it work?
 
if(mysqli_connect_error()) {
 
    die("Mysql Could Not Connect Because " . mysqli_connect_error());
 
}
 
 
 
?>
 

Benden

maging ang maganda mamatay
Jun 4, 2010
2,285
1,482
Why put the mysql in another file? Why not keep them together???
Just add a comment saying //DONT FAKIN TOUCH THIS SHIT
 
Status
Not open for further replies.

Users who are viewing this thread

Top