PDA

View Full Version : Database compatibility


usban
10-02-2002, 07:14 PM
Well i am doing an aplication whith PHP and Access, in the future probably i will have to change the database, so in order to make it an easy step i have tried to build an little file with the functions i use to connect and work with the database, in this file i give a name to all the functions and then i do what i want, in all my site i require this file and then call the functions by the name i have given them, so the idea is that if someday i change the database i only have to change this file.

the problem is that i have tried to do it changing the functions to mysql but i have found that functions that has the same name don't do the same, i mean odbc_fetch_row and mysql_fetch_row don't return the same, the first one returns an integer and the second an array. I'm trying to found the equivalents in mysql for the following funtions:

int odbc_fetch_row(int result_id [, int row_number])

and

string odbc_result ( int result_id, mixed field)

If someone know which are the equivalents or have any idea of how combine some of the mysql functions to get it, it wolul be helpful.
:confused:

arik00
10-03-2002, 05:10 AM
i you fetch a row using mysql_fetch_row. and you selected more that one field you need to use the list function, for example:

$q = mysql_query("SELECT ID, Name FROM people");
list($ID,$Name) = mysql_fetch_row($q)

or while
while(list($ID,$Name) = mysql_fetch_row($q)) {
blah
}


and you could just do some select queries, you don't have to use that odbc_result...

Arik
:p

firepages
10-03-2002, 05:19 AM
Database abstraction is always a compromise and almost always innefficient.

You can grab any number of database abstraction routines from script resources on the net - http://www.hotscripts.com/PHP has a few - or you could use PEAR http://pear.php.net

The problem with database abstraction is as you note - different DB's have different implementations of the ANSI standard, the only way around this is for your database classes to use the most basic query types to return a result, somethime this means making 2 or more queries to cover what couls be accomplished with 1 query using the native conection functions.

ODBC :( is as slow as guts & accessing ODBC via an abstraction layer does not help :)

anyway also check out the DBX functions which are PHP,s idea of a generic API , they cover MySQL, PostgreSQL, Microsoft SQL Server, FrontBase, Sybase-CT and ODBC http://www.php.net/dbx - you will soon see though how limiting it is.