mirror of
https://git.code.sf.net/p/quake/website
synced 2024-12-02 17:12:20 +00:00
86 lines
No EOL
2.2 KiB
PHP
86 lines
No EOL
2.2 KiB
PHP
<?
|
|
/*
|
|
sql.php
|
|
|
|
SQL function library
|
|
|
|
Copyright (C) 2001-2007 Jeff Teunissen <deek@quakeforge.net>
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to:
|
|
|
|
Free Software Foundation, Inc.
|
|
59 Temple Place - Suite 330
|
|
Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
have ('sql');
|
|
|
|
function sqlReadQuery ($query)
|
|
{
|
|
global $sqlError;
|
|
|
|
$ret = null;
|
|
$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;
|
|
}
|
|
@mysql_free_result ($result);
|
|
} 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)) { // Success
|
|
$ret = @mysql_affected_rows ($conn);
|
|
@mysql_free_result ($result);
|
|
} else { // Query failed.
|
|
$sqlError = @mysql_error ();
|
|
$ret = false;
|
|
}
|
|
} else { // Couldn't even connect.
|
|
if (sqlAvail && defined ('sqlRWUser') && defined ('sqlRWPass'))
|
|
$sqlError = @mysql_error ();
|
|
else
|
|
$sqlError = "Cannot write to database.";
|
|
}
|
|
@mysql_close ($conn);
|
|
return $ret;
|
|
}
|
|
?>
|