//---------------------------
// LIBRARY - Mysql db tools
//--------------------------
require_once("L_defs_ip.php");
require_once("L_error_ip.php");
function shutdown_connections ()
{
if (connection_status()!=0){
mysql_close();
}
}
register_shutdown_function("shutdown_connections");
//.......................................................................
//
// Some queries can be problematic because they are larger than the
// space in RAM inwhich to buffer them. This will cause the query to
// fail. So ... we need, first, to flip on a flag in mysql that tells
// mysql to buffer the queries to disk instead of RAM. The command to
// do this is:
//
// SET SQL_BIG_TABLES=1;
//
// You can then run the large query, and then, promptly,
// turn this feature off with:
//
// SET SQL_BIG_TABLES=0;
//
// The function below takes "ON" and "OFF" as args which perform the actions
// mentioned above.
//
// -The globals need to be defined in defs.php
//
// bigtables([ON|OFF]) - returns 0 upon success.
//
function bigtables($action="ON")
{
global $HOST, $USER, $PASSWD, $DB, $OK, $ERROR;
connect();
$query = "SET SQL_BIG_TABLES=";
if( $action === "ON" )
$query .= "1";
else if( $action === "OFF" )
$query .= "0";
else
return $ERROR;
//print "**$query"; br();
if( !mysql_query($query) )
{
print "Error querying $DB, query = $query";
err_log("Error querying $DB, query = $query");
if ( !connection_status() )
mysql_close();
exit($ERROR);
}
return $ERROR;
}
//
// types: s=string, n=number
//
function clean_variable($var, $type="s", $do_escape=true, $empty_ret_val="\N")
{
// First off, if the variable is empty, we want to return the
// $empty_ret_val value.
// This could use some more work but in its current state,
// should be helpful with cleaning up variables that
// need to go into mysql.
if( $type == "s" )
{
//print "len of eleg: " . strlen($var) . "
";
if( strlen($var) == 0 )
return $empty_ret_val;
else
{
if( $do_escape )
return "\"" . mysql_escape_string($var) . "\"";
else
return "\"" . $var . "\"";
}
}
else if( $type == "n" )
{
// apparently this is one way to obtain the string length
// of a number.
if( strlen( strval($var) ) == 0 )
return $empty_ret_val;
else
return $var;
}
else
{
// If we don't know what to do with the variable, just return it
// in hopes that things will continue on fine.
return $var;
}
}
//-------------------------------------------------------------------------------------------
// defs.php needs to define $HOST, $USER, $PASSWD, $DB, $MYSQL_CON_ERR, and $MYSQL_SELECT_ERR
function connect()
{
global $HOST, $USER, $PASSWD, $DB, $MYSQL_CON_ERR, $MYSQL_SELECT_ERR, $RED;
// Connect to database.
if ( ! @mysql_connect($HOST, $USER, $PASSWD) )
{
$errmsg = "Error connecting to $HOST as $USER: " . mysql_error();
print "