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);
?>

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.