Jump to content

Most Secure Way to Connect to a MySQL Database?


Far Cry

Recommended Posts

Hi there, I have this connect script I have made. I was wondering if it's secure or not, if not... What would be a good way to do so...

<?php
class connect{
public $host = "localhost";
public $dbuser = "";
public $dbpass = "";
public $db = "";
}
$connect = new connect();

mysql_connect($connect->host,$connect->dbuser,$connect->dbpass) or die("Could not connect!");
mysql_select_db($connect->db);
?>

 

not sure why you'd use a class, but it's as secure as it can be considering a connection to localhost.

 

Well, I want to make sure it's as secure as can be before I upload it to my live server :)

 

Using a class in the way you have doesn't enhance security, as far as I know.

 

 

Close any script that uses mysql with

mysql_close($link);

 

This is not necessary, as PHP automatically closes the connection at the end of script execution. See:

 

http://php.net/manual/en/function.mysql-close.php

 

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.