2000-05-10 22:38:21 +00:00
|
|
|
<?
|
2007-03-18 04:34:44 +00:00
|
|
|
/*
|
|
|
|
sql.php
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
SQL function library
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
Copyright (C) 2001 Jeff Teunissen <deek@quakeforge.net>
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
See the GNU General Public License for more details.
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2007-03-18 04:34:44 +00:00
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
have ('sql');
|
|
|
|
|
|
|
|
function sqlReadQuery ($query)
|
|
|
|
{
|
|
|
|
$ret = null;
|
|
|
|
|
|
|
|
global $sqlError;
|
|
|
|
|
|
|
|
$sqlError = null; // always set SQL error condition
|
|
|
|
|
|
|
|
if (sqlAvail && $conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass)) {
|
|
|
|
if ($result = @mysql_db_query (sqlDB, $query, $conn)) {
|
|
|
|
if ($numRows = @mysql_num_rows ($result)) {
|
|
|
|
for ($i = 0; $i < $numRows; $i++) {
|
|
|
|
$ret[$i] = @mysql_fetch_assoc ($result);
|
|
|
|
}
|
|
|
|
} else { // Successful query, no rows returned.
|
|
|
|
$ret = true;
|
|
|
|
}
|
|
|
|
} else { // Query failed.
|
|
|
|
$sqlError = mysql_error ();
|
|
|
|
$ret = false;
|
|
|
|
}
|
|
|
|
mysql_close ($conn);
|
|
|
|
} else { // Couldn't even connect.
|
|
|
|
if (sqlAvail)
|
|
|
|
$sqlError = mysql_error ();
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sqlWriteQuery ($query)
|
|
|
|
{
|
|
|
|
$ret = null;
|
|
|
|
|
|
|
|
global $sqlError;
|
|
|
|
|
|
|
|
$sqlError = null; // always set SQL error condition
|
|
|
|
|
|
|
|
if (sqlAvail
|
|
|
|
&& defined (sqlRWUser)
|
|
|
|
&& defined (sqlRWPass)
|
|
|
|
&& $conn = @mysql_pconnect (sqlHost, sqlRWUser, sqlRWPass)) {
|
|
|
|
if ($result = @mysql_db_query (sqlDB, $query, $conn)) {
|
|
|
|
if ($numRows = @mysql_affected_rows ($result)) { // Success
|
|
|
|
$ret = $numRows;
|
|
|
|
}
|
|
|
|
} else { // Query failed.
|
|
|
|
$sqlError = @mysql_error ();
|
|
|
|
$ret = false;
|
|
|
|
}
|
|
|
|
@mysql_close ($conn);
|
|
|
|
} else { // Couldn't even connect.
|
|
|
|
if (sqlAvail && defined (sqlRWUser) && defined (sqlRWPass))
|
|
|
|
$sqlError = @mysql_error ();
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
?>
|