PHP4's class system sucks major cock, but it is still rather useful.
index.php
CODE
require_once ("core/mysql.php");
$sql = new mysql;
Then anywhere in another class, I can call shit like:
CODE
function stupid_insert_function()
{
global $vars, $sql;
$sql->insert('sessions', array(
'id' => $vars->session['id'],
'mid' => $vars->member['id'],
'ip' => $vars->session['ip'],
'browser' => $vars->session['browser'],
'running' => $vars->time,
'cloak' => $c_cloak,
'key' => $vars->session['key']
));
}
-or like previous stated-
CODE
$sql->query("SELECT * FROM members WHERE id={$row['v_mid']}");
$vars->member = $sql->fetch();
The sql class's function for insert() simply takes my variables / arrays and converts it into a real sql insert query. It's a lot more organized and cleaner than a billion sql queries.
I used to do it the same way as you until I started coding inside invision. It is truly time efficent, more organized, and generally just cleaner. It also allows for some wicked stuff if you know what you are doing
.
As far as using functions, generally, if you ever find yourself copy and pasting the same line(s) of code, it's probably better off in a function of some sort.
Other things:
One of the most useful things EVER that invision taught me about php is <<<
$temp = <<<EOF
I can use any f"!'$%ng characters I want in here without back slashing them!
EOF;
Very, very useful when dealing with html...
as well as...
$temp = "My string containing {$my_variable} = a little string";
It's a hell of a lot easier than doing...
$temp = "My string containing" . $my_variable . " = a little string";
when you have a lot of different variables.