I wrote this function about 2 years ago when I started in PHP, I haven't touched PHP since so im still not an expert, but I would like to know what people thought of it, and if was any good / secure / fast / easy to use ect ect
Looking for some constructive criticism really and improvements and faults.
Thanks
[PHP]<?php
// Database Function
function db($Action) {
$Username = '';
$Password = '';
$Database = '';
$Host = 'localhost';
if ( $Action == 'open' ) {
mysql_connect($ Host, $Username, $Password) or die ( 'Unable to connect to the server. This may be because the server does not exsist, or the username and password given was incorrect. Please check and try again.<br>' );
mysql_select_db ($Database) or die ( 'Unable to select the database. Database does not exsist. Please check and try again.<br>' );
} else if ( $Action == 'close' ) {
mysql_close() or die ( 'Unable to disconnect from the server. Maybe there was no connection to disconnect from?<br>' );
} else {
echo 'The handle that was sent is not valid. Please check and try again.<br>';
}
}
function query($query, $line) {
global $queries, $queries_time, $queries_count;
$queries_count+ +;
// Add the query to the queries list. Dont add a break at the end in case an error occurred
$queries .= 'Line <b>'. $line . '</b> of file <b>' . $_SERVER['PHP_SELF'] . '</b> requested <b>' . $query . '</b>';
// Do the query if it can
$time_overall = round(microtime (), 15);
if (!$result = mysql_query($qu ery)) {
echo 'Error on line <b>'. $line . '</b> of file <b>' . $_SERVER['PHP_SELF'] . '</b> requesting <b>' . $query . '</b><br>';
$queries .= ' <b>ERROR OCCURRED</b><br>';
} else {
$queries .= '<br>';
}
$time2_overall = round(microtime (), 15);
$gen_overall = $time2_overall - $time_overall;
$queries_time = $queries_time + $gen_overall ;
return $result;
}
?>[/PHP]
Looking for some constructive criticism really and improvements and faults.
Thanks
[PHP]<?php
// Database Function
function db($Action) {
$Username = '';
$Password = '';
$Database = '';
$Host = 'localhost';
if ( $Action == 'open' ) {
mysql_connect($ Host, $Username, $Password) or die ( 'Unable to connect to the server. This may be because the server does not exsist, or the username and password given was incorrect. Please check and try again.<br>' );
mysql_select_db ($Database) or die ( 'Unable to select the database. Database does not exsist. Please check and try again.<br>' );
} else if ( $Action == 'close' ) {
mysql_close() or die ( 'Unable to disconnect from the server. Maybe there was no connection to disconnect from?<br>' );
} else {
echo 'The handle that was sent is not valid. Please check and try again.<br>';
}
}
function query($query, $line) {
global $queries, $queries_time, $queries_count;
$queries_count+ +;
// Add the query to the queries list. Dont add a break at the end in case an error occurred
$queries .= 'Line <b>'. $line . '</b> of file <b>' . $_SERVER['PHP_SELF'] . '</b> requested <b>' . $query . '</b>';
// Do the query if it can
$time_overall = round(microtime (), 15);
if (!$result = mysql_query($qu ery)) {
echo 'Error on line <b>'. $line . '</b> of file <b>' . $_SERVER['PHP_SELF'] . '</b> requesting <b>' . $query . '</b><br>';
$queries .= ' <b>ERROR OCCURRED</b><br>';
} else {
$queries .= '<br>';
}
$time2_overall = round(microtime (), 15);
$gen_overall = $time2_overall - $time_overall;
$queries_time = $queries_time + $gen_overall ;
return $result;
}
?>[/PHP]
Comment