Being a programmer I've been asked to support a non-profit's web-site. The site was developed using php and mysql. I've installed apache 2.2, mysql 5 and php5.2.4 on my local machine.
I've copied files over from the non-profit's website. However I'm having problems with connecting to the database. The primary file is a file called txt_db_api with supporting files.
I've been able to subsitute the "executeQuery" with mySQL_query. And also have been able to use mySQL_result. To get the queries back. But any code that goes back to txt_db_api bombs.
So I'm wondering if this an issue with different versions of PHP?
The only thing I can find about txt_db_api is on this website. http://www.c-worker.ch/txtdbapi/index_eng.php
I can change the code on my end - so that I can learn it - but I think if this is about compatibility than I might just have opened a can of worms. I also need to verify what version of PHP the host provider suppports.
I'd appreciate any insight that can be offered here.
I'm new to PHP and my programming background is not OO.
Thanks.
Vic
What is txt_db_api
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah,
Since I found a copy of it out on the web - I would be surprised that it was created by the original developer of the site I'm looking at. But here's an example
Actually it looks like "executeQuery" is in a php file called database.php. I'm a little hesitant to post the code - but here goes.
So far - I haven't been able to get any of the original database connections/queries to work - but when I replace them with mySql_query they work.
I was hoping this would look familiar to someone else. Hopefully none of the changes I'll be asked to make will involve the sql code. I don't mind changing it on my end - helps me with the learning process.
Thanks.
Vic
Since I found a copy of it out on the web - I would be surprised that it was created by the original developer of the site I'm looking at. But here's an example
Code: Select all
//vwc $rs = $txtdb->executeQuery("SELECT * FROM t_dates WHERE index = '0'");
$rs = mysql_query("SELECT * FROM t_dates");Code: Select all
// $sql_query_str is an unparsed SQL Query String
// Return Values:
// SELECT Queries: Returns a ResultSet Object or false
// CREATE TABLE: Returns true or false
// All other types: Returns the number of rows affected
function executeQuery($sql_query_str) {
set_error_handler("txtdbapi_error_handler");
txtdbapi_clear_errors();
debug_printb("[executeQuery] Query: $sql_query_str<br>");
// Parse Query
$start=getmicrotime();
$sqlParser=new SqlParser($sql_query_str);
$sqlQuery=$sqlParser->parseSqlQuery();
debug_print("parseSqlQuery: " . (getmicrotime() - $start) . " seconds elapsed<br>");
// free $sqlParser
unset($sqlParser);
$sqlParser="";
// Test Query
if((!$sqlQuery) || (!$sqlQuery->test())) {
restore_error_handler();
return false;
}
$start=getmicrotime();
debug_printb("[executeQuery] Parsed Query:<br>");
if(TXTDBAPI_DEBUG) {
$sqlQuery->dump();
}
// Dispatch
switch($sqlQuery->type) {
case "SELECT":
$rc=$this->executeSelectQuery($sqlQuery);
break;
case "INSERT":
$rc=$this->executeInsertQuery($sqlQuery);
break;
case "DELETE":
$rc=$this->executeDeleteQuery($sqlQuery);
break;
case "UPDATE":
$rc=$this->executeUpdateQuery($sqlQuery);
break;
case "CREATE TABLE":
$rc=$this->executeCreateTableQuery($sqlQuery);
break;
case "DROP TABLE":
$rc=$this->executeDropTableQuery($sqlQuery);
break;
case "CREATE DATABASE":
$rc=$this->executeCreateDatabaseQuery($sqlQuery);
break;
case "DROP DATABASE":
$rc=$this->executeDropDatabaseQuery($sqlQuery);
break;
case "LIST TABLES":
$rc=$this->executeListTablesQuery($sqlQuery);
break;
default:
print_error_msg("Invalid or unsupported Query Type: " . $sqlQuery->type);
restore_error_handler();
return false;
}
if(is_false($rc)) {
print_error_msg("Query '" . $sql_query_str . "' failed");
}
debug_printb("[executeQuery] Query execution done: " . (getmicrotime() - $start) . " seconds elapsed<br>");
restore_error_handler();
return $rc;
}I was hoping this would look familiar to someone else. Hopefully none of the changes I'll be asked to make will involve the sql code. I don't mind changing it on my end - helps me with the learning process.
Thanks.
Vic
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Somewhere in the application there is a class that is instantiated into an object called $txtdb. The code you posted is from that class. What you are working with is what is called a DB abstraction interface (or something similar to that). Basically someone wrote a handler that adds more flexibility and power to the app than the base mysql_* functions normally offer.
executeQuery is a method of the $txtdb object, which happens to be an instance of whatever class it is being instantiated from. I would guess that the database.php file has the entire class in it.
executeQuery is a method of the $txtdb object, which happens to be an instance of whatever class it is being instantiated from. I would guess that the database.php file has the entire class in it.