Page 1 of 1
Server resources
Posted: Tue Jul 22, 2003 7:34 pm
by Alcor
I have a PHP server and I'm developping a Secure web site with data base transactions. Perhaps my question look stupid because I'm starting with PHP.
When I create my PHP script for DB transactions, is it better to create a big script with all the Add, Mod, Del, ... command or to create a number of smaller script with each DB transactions in it? I want to know that because I need to optimise the answer delay on my server.
If you have informations, let me know !
Thanks !
Sorry for my english, I'm french Canadian !

Posted: Tue Jul 22, 2003 7:38 pm
by qartis
By "DB transactions", do you mean the individual queries, or functions FOR DB transactions? Unless you're developing a gigantic application, it's safe to have the connection calls included at the beginning, individual queries by themselves, and close the db connection at the end (especially if you're new to php)
PS: On peut parler du francais quebecois, si vous voulez

Posted: Tue Jul 22, 2003 7:43 pm
by Gen-ik
If you want to keep things tidy and fast you can always create a collection of .php files ( such as mod.php, del.php, add.php etc ) for your database functions and then just include() the ones you need when you need them.
Here's an example......
This is the add.php file
Code: Select all
<?php
function add_to_database($table, $name, $email)
{
mysql_query(" INSERT INTO $table VALUES ('$name','$email') ");
}
?>
And this is part if the main page...
Code: Select all
<?php
If(isset($action) && $action=='add')
{
include("add.php");
add_to_database('tablename','bob','bob@home.co.uk');
}
?>
Something like that anyway
Using include() is always good because it means you don't have to load up every single function and/or php code at once, and it normally (if used in the right way) will speed up your page run/load times.
Posted: Tue Jul 22, 2003 7:54 pm
by qartis
Code: Select all
<?php
function add_to_database($table, $name, $email)
{
mysql_query(" INSERT INTO $table VALUES ('$name','$email') ");
}
?>
Good principle, bad example
If you don't need to be so specific (and want to avoid an entire class), you should be able to get away with something like
/inc/db/select.php:
Code: Select all
<?
function db_select($feilds_array,$table,$where){
foreach($feilds_array as $name){
(isset($feilds))?$feilds.=",";
$feilds.="`$name`";
}
return (mysql_query("SELECT $feilds FROM `$table` WHERE $where"))?true:false;
}
?>
Don't use that, though, it's probably full of errors. I just wanted to type something up to show you that it's *possible*, but not really necessary (YMMV)
Thanks !
Posted: Tue Jul 22, 2003 7:59 pm
by Alcor
Thanks for your answers qartis and Gen-ik. It's appreciated.
When I will be better with PHP, I will undoubtedly come here to help other PHP developper.
Thanks a lot !!!