PHPBuilder - Cross-platform and Portable Development With PHP Page 4



RSS Twitter
Articles Databases

Cross-platform and Portable Development With PHP - Page 4

by: PHP Builder Staff
|
July 20, 2001

A common set of interface functions is then included, as shown below:

<?

// Lots of stuff to give a database interface that is relatively
// independent of the underlying functions. No doubt this has
// been done elsewhere, but at present I don't have access to it.
// These globals need wrapping up as an object asap
//
//

include 'config.php';

$DBdebug 0;

if(
$DBms == "mysql"){
        
$DBconnect "mysql_connect";
        
$DBselect_db "mysql_select_db";
        
$DBquery "mysql_query";
        
$DBfetch_array "mysql_fetch_array";
        
$DBfetch_object "mysql_fetch_object";
        
$DBfetch_row "mysql_fetch_row";
        
$DBerror "mysql_error";
        
$DBnum_fields "mysql_num_fields";
        
$DBlist_fields "mysql_list_fields";
        
$DBsql_char_length "Char_Length";
}elseif(
$DBms == "mssql"){
        
$DBconnect "mssql_connect";
        
$DBselect_db "mssql_select_db";
        
$DBquery "mssql_query";
        
$DBfetch_array "mssql_fetch_array";
        
$DBfetch_object "mssql_fetch_object";
        
$DBfetch_row "mssql_fetch_row";
        
$DBerror "mssql_error";
        
$DBnum_fields "mssql_num_fields";
        
$DBlist_fields "mssql_list_fields";
        
$DBsql_char_length "DataLength";
}

function 
DBconnect($host$username$password){
        global 
$DBconnect$DBdebug;
        if(
$DBdebug)echo "DBconnect is $DBconnect\n";;
        
$rval $DBconnect($host$username$password);
        if(
$DBdebug)echo "Result of DBconnect is $rval\n";
        return 
$rval;
}

function 
DBuse($dbname$connection){
        global 
$DBselect_db$DBdebug;
        
$rval $DBselect_db($dbname$connection);
        if(
$DBdebug)echo "Result of DBuse is $rval\n";
        return 
$rval;
}
function 
DBquery($query$connection){
        global 
$DBquery$DBdebug;
        if(
$DBdebug)echo "<br>\nQuery: $query";
        
$rval $DBquery($query$connection);
        if(
$DBdebug)echo "<br>\nResult: $rval.";
        return 
$rval;
}
function 
DBerror($connection){
        global 
$DBerror$DBdebug;
        
$rval $DBerror($connection);
        if(
$DBdebug)echo "Result of error() is $rval\n";
        return 
$rval;
}
function 
DBfetch_array($resultid){
        global 
$DBfetch_array$DBdebug;
        
$rval $DBfetch_array($resultid);
        if(
$DBdebug)echo "Result of fetch_array is $rval\n";
        return 
$rval;
}
function 
DBfetch_object($resultid){
        global 
$DBfetch_object$DBdebug;
        
$rval $DBfetch_object($resultid);
        if(
$DBdebug)echo "Result of fetch_object is $rval\n";
        return 
$rval;
}
function 
DBfetch_row($resultid){
        global 
$DBfetch_row$DBdebug;
        
$rval $DBfetch_row($resultid);
        if(
$DBdebug)echo "Result of fetch_row is $rval\n";
        return 
$rval;
}
function 
DBnum_fields($resultid){
        global 
$DBnum_fields$DBdebug;
        
$rval $DBnum_fields($resultid);
        if(
$DBdebug)echo "Result of num_fields is $rval\n";
        return 
$rval;
}
function 
DBlist_fields($resultid){
        global 
$DBlist_fields$DBdebug;
        
$rval $DBlist_fields($resultid);
        if(
$DBdebug)echo "Result of list_fields is $rval\n";
        return 
$rval;
}
function 
DBaux_show_array($array$sep "\n"){
        while(list(
$k,$v) = each($array)){
                echo 
"Key $k has value $v $sep";
        }
}

// Concatenating strings is different for MySQL and SQL Server
function DBconcat($words)
{
        global 
$DBms;

        if (
$DBms == 'mssql')
                return 
preg_replace('/ /'' + '$words);
        else
                return 
'Concat(' preg_replace('/ /'', '$words) . ')';
}

?>

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
|
7
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:

Comment:



Comment:

(Maximum characters: 1200). You have characters left.