Skip to content

Instantly share code, notes, and snippets.

@simeondahl
Created January 9, 2013 21:55
Show Gist options
  • Select an option

  • Save simeondahl/4497315 to your computer and use it in GitHub Desktop.

Select an option

Save simeondahl/4497315 to your computer and use it in GitHub Desktop.
Secure MySQL-connect script.
<?php
// Mysql settings
$mysql['enabled'] = true; // Enable MySQL
$mysql['host'] = "localhost"; // Host
$mysql['user'] = "root"; // Username
$mysql['pass'] = "1234"; // Password
$mysql['db'] = "my_base"; // Database
?>
<?php
require("config.php");
// If mysql is enabled, then it will go further
if ($mysql['enabled']) {
$mysql['user'] = mysql_real_escape_string($mysql['user']);
$mysql['pass'] = mysql_real_escape_string($mysql['pass']);
$con = mysql_connect( $mysql['host'] , $mysql['user'] , $mysql['pass'] , $mysql['db'] );
if (!$con) {
die("Can't connect to MySQL: ". mysql_error());
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment