Ok.. So I've been developing an SQL app with PHP. It's basically just for those poor people who can't get access to a MySQL database or are looking for an SQL system with less complication for faster results for applications such as chat systems (Basically the speed difference is how long it takes for a query to run compared to editing a file... HUGE difference).
My problem is I've been developing the error reporting and it works pretty much exactly like MySQLs error reporting. It's just a function in which a value is returned that contains the error. The only problem is getting that error to appear.
In MySQL to connect and have the error show if one is encountered you might do it like this -
PHP Code:
$connection = mysql_connect('host', 'user', 'pass') or die ('Unable to connect to database because: ' . mysql_error());
This is how I want it to work for my app. The only problem is there's a problem with the "or die" part of the function. I figured or die means if the function returns false then stop script execution and show this message but it dies even when the function returns true. So does anyone know EXACTLY how or die works so I can make this work?
O also this is how the functions I'm using look like -
Call to function -
PHP Code:
require ('./functions.php'); $txtsql = new txtSQLfunctions; $txtsql->connect('/mmmsoftware/projects/textSQL/db_1', 'Matt', 'pass') or die ($txtsql->latest_error());
Function being called -
PHP Code:
// Database connection handler function connect($db_location, $db_user, $db_pass) { // Clean up info given... $db_user = strtolower($db_user); $db_loc_last_char = substr($db_location, strlen($db_location) - 1, strlen($db_location)); if ($db_loc_last_char != '/' && $db_loc_last_char != '\\') { $db_location .= '/'; } if (substr($db_location, 0, 7) != 'http://' && substr($db_location, 0, 1) != '/' && substr($db_location, 0, 2) != './') { $db_location = 'http://' . $db_location; } // Already connected to another DB? if (isset($this->connection_info['db_location']) && $this->connection_info['db_location'] != $db_location) { $this->latest_error = "<b>TextSQL <i><font color='red'>beta</font></i> Error:</b> Already connected to another database. Please close first connection before opening a new one. Support for multiple connections will come in a later version."; } if ($this->connection_info['db_location'] == $db_location && $this->connection_info['db_user'] == $db_user && $this->connection_info['db_pass'] == $db_pass) { // Lol dude you're already connected to that db. Just re-use past connection info. $this->latest_error .= "<br />NO FATAL ERRORS REPORTED"; return (true); } else { if (is_file($db_location . 'txtsql_db_info.php.inc')) { require($db_location . 'txtsql_db_info.php.inc'); if (isset($USERS[$db_user])) { $pass_perm = explode('-|*|-', $USERS[$db_user]); if ($pass_perm[0] == $db_pass) { // Connection info valid!!! } else { // Invalid password $this->latest_error = "<b>TextSQL <i><font color='red'>beta</font></i> Error:</b> Invalid password for user given. Connection failed."; $this->connection_info = array(); return (false); } } else { $this->latest_error = "<b>TextSQL <i><font color='red'>beta</font></i> Error:</b> The user you attempted to use does not exist."; $this->connection_info = array(); return (false); } } else { $this->latest_error = "<b>TextSQL <i><font color='red'>beta</font></i> Error:</b> Database files do not exist in specified directory or the databases info file was destroyed."; $this->connection_info = array(); return (false); } } }
Error function -
PHP Code:
function latest_error() { return ("test " . $this->latest_error); }
Thanks a lot  .
__________________
PHP Code:
$talkupation++;
Please login or register to view this content. Registration is FREE - Free IPB forum hosting (releasing today!!!), no ads, free modifications
Last edited by Mattmaul1992; 01-12-2008 at 03:33 PM..
|