$dc = da_openConnection();
$cursor = da_openCursor();
// open db connection
function da_openConnection()
{
global $da_config;
$dc = sqlrcon_alloc( $da_config["dbhost"],
9000, "", $da_config["dbuser"], $da_config["dbpassword"], 0, 1);
return $dc;
}
// open cursor
function da_openCursor()
{
global $dc;
$cursor = sqlrcur_alloc( $dc );
return $cursor;
}
function da_closeCursor()
{
global $cursor;
sqlrcur_free( $cursor );
}
// close db connection, but never close because we use a persistent connection
// and delegate connection management to php4.
function da_closeConnection()
{
global $dc;
da_closeCursor();
sqlrcon_free( $dc );
}
function da_queryValue($query)
{
global $dc;
global $cursor;
$query = stripSlashes($query);
sqlrcur_sendQuery( $cursor, $query );
sqlrcon_endSession( $dc );
$row = sqlrcur_getField( $cursor, 0, 0 );
return $row;
}
// sqlrelay API를 사용한 da_queryScalar
function da_queryScalar($query)
{
global $dc;
global $cursor;
sqlrcur_sendQuery( $cursor, $query );
sqlrcon_endSession( $dc );
return sqlrcur_rowCount( $cursor );
}
// MySQL API를 사용한 da_queryScalar
function da_queryScalar($query)
{
global $dc;
$rows = @mysql_query($query, $dc);
return @mysql_num_rows($rows);
}
function da_queryNonResult($query)
{
global $dc;
global $cursor;
sqlrcur_sendQuery( $cursor, $query );
sqlrcon_endSession( $dc );
return sqlrcur_affectedRows( $cursor );
}
function da_getRecordsByFields($query)
{
global $dc;
global $cursor;
$query = stripSlashes($query);
// buffering the result set all at once
sqlrcur_setResultSetBufferSize( $cursor, 0 );
sqlrcur_sendQuery( $cursor, $query );
sqlrcon_endSession( $dc );
if ( 0 == $cursor )
{
return false;
exit;
}
for( $loopctr = 0; $loopctr < sqlrcur_rowCount( $cursor ); $loopctr++)
{
$row_array = sqlrcur_getRow( $cursor, $loopctr );
for( $ctr = 0; $ctr < sqlrcur_colCount( $cursor ); $ctr++ )
{
$field_name = sqlrcur_getColumnName( $cursor, $ctr );
$data_set[$loopctr][$field_name] = $row_array[$ctr];
}
}
// end da_getRecords
return $data_set;
}
sqlrcur_setResultSetBufferSize( $cursor, 0 );
function da_fetchArray( $res, $row )
{
return sqlrcur_getRowAssoc( $res, $row );
}
if( $da_config["dbms"] == "php5mysql" )
{
require( "/lib/database-php5mysql.inc.php");
}
else if( $da_config["dbms"] == "php4mysql" )
{
require( "/lib/database-php4mysql.inc.php" );
}
else
{
require( "/lib/database-php4mysql.inc.php" );
}
else if( $da_config["dbms"] == "sqlrelay" )
{
require( "/lib/database-sqlrelay.inc.php" );
}
이전 글 : 윈도우 XP SP2 호환성 문제를 위한 조언
다음 글 : 피보나치에 대한 이야기
최신 콘텐츠