TinyPortal

Development => Support => Topic started by: Heero on July 31, 2008, 07:29:47 PM

Title: Fast question : are blocks safe enough?
Post by: Heero on July 31, 2008, 07:29:47 PM
Well hey again,
I'm here with a fast question.
Since I want to use a script that includes my database name + password,
I'd like to know if its safe?
The script looks as followed :

$link = mysql_connect('localhost','databasename', 'password') or die('Could not connect: ' . mysql_error());
mysql_select_db('database_smf') or die('Could not select database');
$querydl = 'select * From `reps_table` order by Downloads DESC limit 0,3';
$resultdl = mysql_query($querydl) or die('Query failed: ' . mysql_error());
$querylast = 'select * From `reps_table` order by `Datum` DESC limit 0,3';
$resultlast = mysql_query($querylast) or die('Query failed: ' . mysql_error());
$queryrand = 'select * From `reps_table` ORDER BY RAND()  limit 0,3';
$resultrand = mysql_query($queryrand) or die('Query failed: ' . mysql_error());


Thanks in advance.
Title: Re: Fast question : are blocks safe enough?
Post by: Ianedres on July 31, 2008, 07:54:42 PM
SMF provides the db_query function (http://support.simplemachines.org/function_db/index.php?action=view_function;id=206) to interact with the database safely and securely.
Title: Re: Fast question : are blocks safe enough?
Post by: G6Cad on July 31, 2008, 08:02:27 PM
It should be safe yes.
Title: Re: Fast question : are blocks safe enough?
Post by: IchBin on July 31, 2008, 08:21:29 PM
I don't think you'll be able to connect to another base within TP. PHP can only make a connection to one database per request. If you are using SMF's DB, then you don't need to use any of those connection functions. Just use db_query() to call query the DB as Ianedres said.
Title: Re: Fast question : are blocks safe enough?
Post by: Heero on July 31, 2008, 08:34:13 PM
Okay, thanks for the responses :).
Title: Re: Fast question : are blocks safe enough?
Post by: Ianedres on July 31, 2008, 08:39:52 PM
As a general rule for other scripts, you should 1) put your connection info into a separate script, and 2) stored in a directory off the public webserver with restricted access via your .htaccess file.

You can then include the connection script at the top of your script (and any other scripts), making for one location to store the info and avoid errors...