ACCES INTERZIS | blog de programare si securitate IT




 22 Feb 2010 @ 14:50 

The below PHP script allows you to connect securely to a MySQL database.

<?php
define('SQL_HOST', 'localhost');
define('SQL_USER', 'username');
define('SQL_PASS', 'password');
define('SQL_DB', 'database name');

@mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die('I can`t connect to MySQL server!');
@mysql_select_db(SQL_DB) or die('I can`t connect to database!');
?>

Usually, this script is an include file which is called, mostly above DOCTYPE, whenever a page needs a connection to database.

<?php include("includes/connect_to_db.inc.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Post to Twitter Tweet This Post

Posted By: admin
Last Edit: 22 Feb 2010 @ 15:25

EmailPermalinkComments (0)
Tags
Tags: , ,
Categories: programming