Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
ircbot/databases
515
ircbot/databases/ini.php
Normal file
515
ircbot/databases/ini.php
Normal file
|
@ -0,0 +1,515 @@
|
|||
<?php
|
||||
/*
|
||||
+---------------------------------------------------------------------------
|
||||
| PHP-IRC v2.2.1 Service Release
|
||||
| ========================================================
|
||||
| by Manick
|
||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
||||
| Contact: manick@manekian.com
|
||||
| irc: #manekian@irc.rizon.net
|
||||
| ========================================
|
||||
+---------------------------------------------------------------------------
|
||||
| > ini-file database module
|
||||
| > Module written by Manick
|
||||
| > Module Version Number: 2.2.1 alpha
|
||||
+---------------------------------------------------------------------------
|
||||
| > 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 the Free Software
|
||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
+---------------------------------------------------------------------------
|
||||
| Changes
|
||||
| =======-------
|
||||
| > If you wish to suggest or submit an update/change to the source
|
||||
| > code, email me at manick@manekian.com with the change, and I
|
||||
| > will look to adding it in as soon as I can.
|
||||
+---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ini {
|
||||
|
||||
private $filename;
|
||||
private $error;
|
||||
private $ini = array();
|
||||
private $numSections;
|
||||
|
||||
//used in isMatched()
|
||||
private $search;
|
||||
private $searchParts;
|
||||
|
||||
|
||||
//Load ini into memory
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->error = false;
|
||||
$this->filename = $filename;
|
||||
|
||||
$filePtr = @fopen($filename, "r");
|
||||
|
||||
if ($filePtr === false)
|
||||
{
|
||||
$filePtr = @fopen($filename, "a");
|
||||
|
||||
if ($filePtr === false)
|
||||
{
|
||||
$this->error = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose($filePtr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$fileData = "";
|
||||
|
||||
while (!feof($filePtr))
|
||||
{
|
||||
$fileData .= fread($filePtr, 4096);
|
||||
}
|
||||
|
||||
fclose($filePtr);
|
||||
|
||||
$fileData = str_replace("\r", "", $fileData);
|
||||
|
||||
$lines = explode("\n", $fileData);
|
||||
|
||||
$currSection = "";
|
||||
$this->numSections = 0;
|
||||
|
||||
foreach($lines AS $line)
|
||||
{
|
||||
$line = trim($line);
|
||||
|
||||
$offsetA = strpos($line, "[");
|
||||
$offsetB = strpos($line, "]");
|
||||
|
||||
if ($offsetA === 0)
|
||||
{
|
||||
$currSection = substr($line, 1, $offsetB - 1);
|
||||
$this->numSections++;
|
||||
$this->ini[$currSection] = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($currSection != "")
|
||||
{
|
||||
$offsetC = strpos($line, "=");
|
||||
|
||||
if ($offsetC !== false)
|
||||
{
|
||||
$var = trim(substr($line, 0, $offsetC));
|
||||
$val = substr($line, $offsetC + 1);
|
||||
|
||||
if ($var != "")
|
||||
{
|
||||
$this->ini[$currSection][$var] = $val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ini[$currSection][$line] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getSections()
|
||||
{
|
||||
$sections = array();
|
||||
|
||||
if ($this->numSections == 0)
|
||||
{
|
||||
return $sections;
|
||||
}
|
||||
|
||||
foreach ($this->ini AS $section => $vals)
|
||||
{
|
||||
$sections[] = $section;
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
public function getVars($section)
|
||||
{
|
||||
if (!isset($this->ini[$section]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->ini[$section];
|
||||
}
|
||||
|
||||
public function sectionExists($section)
|
||||
{
|
||||
if (isset($this->ini[$section]) && is_array($this->ini[$section]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSection($section)
|
||||
{
|
||||
return $this->getVars($section);
|
||||
}
|
||||
|
||||
public function randomSection($num = 1)
|
||||
{
|
||||
if ($this->numSections == 0 || $num < 1 || $num > $this->numSections)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_rand($this->ini, $num);
|
||||
}
|
||||
|
||||
public function randomVar($section, $num = 1)
|
||||
{
|
||||
if (!isset($this->ini[$section]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$count = count($this->ini[$section]);
|
||||
|
||||
if ($count == 0 || $num < 1 || $num > $count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_rand($this->ini[$section], $num);
|
||||
}
|
||||
|
||||
|
||||
public function searchSections($search, $type = EXACT_MATCH)
|
||||
{
|
||||
$results = array();
|
||||
|
||||
if (trim($search) == "")
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
if ($this->numSections == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($this->ini AS $section => $vars)
|
||||
{
|
||||
if ($this->isMatched($search, $section, $type))
|
||||
{
|
||||
$results[] = $section;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function searchVars($section, $search, $type = EXACT_MATCH)
|
||||
{
|
||||
$results = array();
|
||||
|
||||
if (trim($search) == "")
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
if (!isset($this->ini[$section]))
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
if ($this->numSections == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($this->ini[$section]) == 0)
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
foreach($this->ini[$section] AS $var => $val)
|
||||
{
|
||||
if ($this->isMatched($search, $var, $type))
|
||||
{
|
||||
$results[] = $var;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function searchSectionsByVar($var, $search, $type = EXACT_MATCH)
|
||||
{
|
||||
$results = array();
|
||||
|
||||
if ($this->numSections == 0)
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
foreach($this->ini AS $section => $vars)
|
||||
{
|
||||
if (isset($vars[$var]))
|
||||
{
|
||||
if ($this->isMatched($search, $vars[$var], $type))
|
||||
{
|
||||
$results[] = $section;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
public function searchVals($section, $search, $type = EXACT_MATCH)
|
||||
{
|
||||
$results = array();
|
||||
|
||||
if (trim($search) == "")
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
if (!isset($this->ini[$section]))
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
if ($this->numSections == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($this->ini[$section]) == 0)
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
foreach($this->ini[$section] AS $var => $val)
|
||||
{
|
||||
if ($this->isMatched($search, $val, $type))
|
||||
{
|
||||
$results[] = $var;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function isMatched(&$needle, &$haystack, $type = EXACT_MATCH)
|
||||
{
|
||||
|
||||
if ($type == EXACT_MATCH)
|
||||
{
|
||||
if ($haystack == $needle)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == CONTAINS_MATCH)
|
||||
{
|
||||
if (strpos(strtolower($haystack), strtolower($needle)) !== false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($search != $this->search)
|
||||
{
|
||||
$this->searchParts = explode(chr(32), $search);
|
||||
$this->search = $search;
|
||||
}
|
||||
|
||||
if ($type == AND_MATCH)
|
||||
{
|
||||
$foundAll = true;
|
||||
|
||||
foreach($this->searchParts AS $part)
|
||||
{
|
||||
if (strpos($val, $part) === false)
|
||||
{
|
||||
$foundAll = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($foundAll == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ($type == OR_MATCH)
|
||||
{
|
||||
foreach($this->searchParts AS $part)
|
||||
{
|
||||
if (strpos($val, $part) !== false)
|
||||
{
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function deleteSection($section)
|
||||
{
|
||||
if (isset($this->ini[$section]))
|
||||
{
|
||||
unset($this->ini[$section]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function deleteVar($section, $var)
|
||||
{
|
||||
if (isset($this->ini[$section]))
|
||||
{
|
||||
if (isset($this->ini[$section][$var]))
|
||||
{
|
||||
unset($this->ini[$section][$var]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function numSections()
|
||||
{
|
||||
return $this->numSections;
|
||||
}
|
||||
|
||||
public function numVars($section)
|
||||
{
|
||||
if (isset($this->ini[$section]))
|
||||
{
|
||||
return count($this->ini[$section]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function setIniVal($section, $var, $val)
|
||||
{
|
||||
if ($this->error == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->ini[$section]))
|
||||
{
|
||||
$this->numSections++;
|
||||
$this->ini[$section] = array();
|
||||
}
|
||||
|
||||
if (strpos($var, "=") !== false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->ini[$section][$var] = $val;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getIniVal($section, $var)
|
||||
{
|
||||
if ($this->error == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->ini[$section])
|
||||
&& isset($this->ini[$section][$var]))
|
||||
{
|
||||
return $this->ini[$section][$var];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Update and write ini to file
|
||||
public function writeIni()
|
||||
{
|
||||
if ($this->error == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->numSections == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$output = "";
|
||||
|
||||
foreach ($this->ini AS $section => $vars)
|
||||
{
|
||||
|
||||
$output .= "[" . $section . "]\n";
|
||||
|
||||
if (count($vars))
|
||||
{
|
||||
foreach ($vars AS $var => $val)
|
||||
{
|
||||
$output .= $var . "=" . $val . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$filePtr = fopen($this->filename, "at");
|
||||
|
||||
if ($filePtr === false)
|
||||
{
|
||||
$this->error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
flock($filePtr, LOCK_EX);
|
||||
|
||||
ftruncate($filePtr, 0);
|
||||
|
||||
if (fwrite($filePtr, $output) === FALSE)
|
||||
{
|
||||
$this->error = true;
|
||||
}
|
||||
|
||||
flock($filePtr, LOCK_UN);
|
||||
|
||||
fclose($filePtr);
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
169
ircbot/databases/mysql.php
Normal file
169
ircbot/databases/mysql.php
Normal file
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
/*
|
||||
+---------------------------------------------------------------------------
|
||||
| PHP-IRC v2.2.1 Service Release
|
||||
| ========================================================
|
||||
| by Manick
|
||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
||||
| Contact: manick@manekian.com
|
||||
| irc: #manekian@irc.rizon.net
|
||||
| ========================================
|
||||
+---------------------------------------------------------------------------
|
||||
| > database module
|
||||
| > Module written by Manick
|
||||
| > Module Version Number: 2.2.0 alpha1
|
||||
+---------------------------------------------------------------------------
|
||||
| > 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 the Free Software
|
||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
+---------------------------------------------------------------------------
|
||||
| Changes
|
||||
| =======-------
|
||||
| > If you wish to suggest or submit an update/change to the source
|
||||
| > code, email me at manick@manekian.com with the change, and I
|
||||
| > will look to adding it in as soon as I can.
|
||||
+---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class mysql {
|
||||
|
||||
private $dbIndex;
|
||||
private $prefix;
|
||||
private $queries = 0;
|
||||
private $isConnected = false;
|
||||
|
||||
private $user;
|
||||
private $pass;
|
||||
private $database;
|
||||
private $host;
|
||||
private $port;
|
||||
|
||||
public function __construct($host, $database, $user, $pass, $prefix, $port = 3306)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->pass = $pass;
|
||||
$this->host = $host;
|
||||
$this->database = $database;
|
||||
$this->port = $port;
|
||||
|
||||
$db = mysql_connect($host . ":" . $port, $user, $pass);
|
||||
|
||||
if (!$db)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$dBase = mysql_select_db($database, $db);
|
||||
|
||||
if (!$dBase)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->prefix = $prefix;
|
||||
$this->dbIndex = $db;
|
||||
$this->isConnected = true;
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return (@mysql_error($this->dbIndex));
|
||||
}
|
||||
|
||||
public function isConnected()
|
||||
{
|
||||
return $this->isConnected;
|
||||
}
|
||||
|
||||
//Call by reference switched to function declaration, 05/13/05
|
||||
private function fixVar($id, &$values)
|
||||
{
|
||||
return mysql_real_escape_string($values[intval($id)-1], $this->dbIndex);
|
||||
}
|
||||
|
||||
public function query($query, $values = array())
|
||||
{
|
||||
|
||||
if (!is_array($values))
|
||||
$values = array($values);
|
||||
|
||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, \$values)", $query);
|
||||
|
||||
$this->queries++;
|
||||
|
||||
$data = mysql_query($query, $this->dbIndex);
|
||||
|
||||
if (!$data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function queryFetch($query, $values = array())
|
||||
{
|
||||
|
||||
if (!is_array($values))
|
||||
$values = array($values);
|
||||
|
||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, &\$values)", $query);
|
||||
|
||||
$this->queries++;
|
||||
|
||||
$data= mysql_query($query, $this->dbIndex);
|
||||
|
||||
if (!$data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return mysql_fetch_array($data);
|
||||
}
|
||||
|
||||
|
||||
public function fetchArray($toFetch)
|
||||
{
|
||||
return mysql_fetch_array($toFetch);
|
||||
}
|
||||
|
||||
public function fetchRow($toFetch)
|
||||
{
|
||||
return mysql_fetch_row($toFetch);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
@mysql_close($this->dbIndex);
|
||||
}
|
||||
|
||||
public function lastID()
|
||||
{
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
public function numRows($toFetch)
|
||||
{
|
||||
return mysql_num_rows($toFetch);
|
||||
}
|
||||
|
||||
public function numQueries()
|
||||
{
|
||||
return $this->queries;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
162
ircbot/databases/postgre.php
Normal file
162
ircbot/databases/postgre.php
Normal file
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
/*
|
||||
+---------------------------------------------------------------------------
|
||||
| PHP-IRC v2.2.1 Service Release
|
||||
| ========================================================
|
||||
| by Manick
|
||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
||||
| Contact: manick@manekian.com
|
||||
| irc: #manekian@irc.rizon.net
|
||||
| ========================================
|
||||
+---------------------------------------------------------------------------
|
||||
| > database module
|
||||
| > Module written by Manick
|
||||
| > Module Version Number: 2.1.1
|
||||
+---------------------------------------------------------------------------
|
||||
| > 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 the Free Software
|
||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
+---------------------------------------------------------------------------
|
||||
| Changes
|
||||
| =======-------
|
||||
| > If you wish to suggest or submit an update/change to the source
|
||||
| > code, email me at manick@manekian.com with the change, and I
|
||||
| > will look to adding it in as soon as I can.
|
||||
+---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class postgre {
|
||||
|
||||
private $dbIndex;
|
||||
private $prefix;
|
||||
private $queries = 0;
|
||||
private $isConnected = false;
|
||||
private $error;
|
||||
|
||||
public function __construct($host, $database, $user, $pass, $prefix, $port = 5432)
|
||||
{
|
||||
$this->error = true;
|
||||
|
||||
$connect = "host=" . $host . " ".
|
||||
"port=" . $port . " ".
|
||||
"dbname=" . $database . " ".
|
||||
"user=" . $user . " ".
|
||||
"password=" . $pass;
|
||||
|
||||
$this->error = pg_connect($connect);
|
||||
|
||||
if (!$this->error)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->prefix = $prefix;
|
||||
$this->dbIndex = $this->error;
|
||||
$this->isConnected = true;
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error === false ? true : false;
|
||||
//return (@mysql_error($this->dbIndex));
|
||||
}
|
||||
|
||||
public function isConnected()
|
||||
{
|
||||
return $this->isConnected;
|
||||
}
|
||||
|
||||
private function fixVar($id, $values)
|
||||
{
|
||||
return pg_escape_string($values[intval($id)-1]);
|
||||
}
|
||||
|
||||
public function query($query, $values = array())
|
||||
{
|
||||
|
||||
if (!is_array($values))
|
||||
$values = array($values);
|
||||
|
||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, &\$values)", $query);
|
||||
|
||||
$this->queries++;
|
||||
|
||||
$data = pg_query($this->dbIndex, $query);
|
||||
|
||||
if (!$data)
|
||||
{
|
||||
$this->error = $data;
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function queryFetch($query, $values = array())
|
||||
{
|
||||
|
||||
if (!is_array($values))
|
||||
$values = array($values);
|
||||
|
||||
$query = preg_replace('/\[([0-9]+)]/e', "\$this->fixVar(\\1, &\$values)", $query);
|
||||
|
||||
$this->queries++;
|
||||
|
||||
$data = pg_query($query, $this->dbIndex);
|
||||
|
||||
if (!$data)
|
||||
{
|
||||
$this->error = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return pg_fetch_array($data);
|
||||
}
|
||||
|
||||
|
||||
public function fetchArray($toFetch)
|
||||
{
|
||||
return pg_fetch_array($toFetch);
|
||||
}
|
||||
|
||||
public function fetchRow($toFetch)
|
||||
{
|
||||
return pg_fetch_row($toFetch);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
@pg_close($this->dbIndex);
|
||||
}
|
||||
|
||||
public function lastID()
|
||||
{
|
||||
//ehhh. don't use this.
|
||||
return null;
|
||||
}
|
||||
|
||||
public function numRows($toFetch)
|
||||
{
|
||||
return pg_num_rows($toFetch);
|
||||
}
|
||||
|
||||
public function numQueries()
|
||||
{
|
||||
return $this->queries;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
148
ircbot/databases/postgres.php
Normal file
148
ircbot/databases/postgres.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/*
|
||||
+---------------------------------------------------------------------------
|
||||
| PHP-IRC v2.2.1 Service Release
|
||||
| ========================================================
|
||||
| by Manick
|
||||
| (c) 2001-2005 by http://phpbots.sf.net/
|
||||
| Contact: manick@manekian.com
|
||||
| irc: #manekian@irc.rizon.net
|
||||
| ========================================
|
||||
+---------------------------------------------------------------------------
|
||||
| > database module
|
||||
| > Module written by Manick
|
||||
| > Module Version Number: 2.1.1
|
||||
+---------------------------------------------------------------------------
|
||||
| > 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 the Free Software
|
||||
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
+---------------------------------------------------------------------------
|
||||
| Changes
|
||||
| =======-------
|
||||
| > If you wish to suggest or submit an update/change to the source
|
||||
| > code, email me at manick@manekian.com with the change, and I
|
||||
| > will look to adding it in as soon as I can.
|
||||
+---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// *** Modified by Nemesis128_at_atarax_dot_org
|
||||
|
||||
class postgresql {
|
||||
|
||||
private $dbRes;
|
||||
private $prefix;
|
||||
private $numQueries = 0;
|
||||
private $isConnected = false;
|
||||
private $error = false;
|
||||
|
||||
private $user;
|
||||
private $pswd;
|
||||
private $dbase;
|
||||
private $host;
|
||||
private $port;
|
||||
|
||||
public function __construct ($user,$pswd,$dbase,$prefix,$host = null,$port = 5432) {
|
||||
|
||||
$this->user = $user;
|
||||
$this->pswd = $pswd;
|
||||
$this->dbase = $dbase;
|
||||
$this->prefix = $prefix;
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
|
||||
$conn_str = '';
|
||||
|
||||
if (!is_null($host)) { // connect thru TCP/IP
|
||||
$conn_str .= 'host='.$host;
|
||||
$conn_str .= ' port='.$port;
|
||||
} // else thru intern sockets
|
||||
$conn_str .= ' user='.$user;
|
||||
$conn_str .= ' password='.$pswd;
|
||||
$conn_str .= ' dbname='.$dbase;
|
||||
|
||||
$this->dbRes = pg_connect($conn_str);
|
||||
|
||||
if (!is_resource($this->dbRes)) {
|
||||
$this->error = 'PgSQL Connection error';
|
||||
return;
|
||||
}
|
||||
|
||||
$this->isConnected = true;
|
||||
}
|
||||
|
||||
public function getError () {
|
||||
if ($this->error) {
|
||||
$err = $this->error."\n\n";
|
||||
return ($err.@pg_last_error($this->dbIndex));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function isConnected () {
|
||||
return $this->isConnected;
|
||||
}
|
||||
|
||||
public static function esc ( $var ) {
|
||||
return pg_escape_string ( $var );
|
||||
}
|
||||
|
||||
public function query ( $query_str ) {
|
||||
|
||||
if (pg_connection_status($this->dbRes) === PGSQL_CONNECTION_BAD) {
|
||||
if (!pg_connection_reset($this->dbRes)) {
|
||||
$this->error = 'Connection lost';
|
||||
$this->isConnected = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->numQueries++;
|
||||
|
||||
$res = @pg_query($this->dbRes,$query_str);
|
||||
|
||||
if (!$res) {
|
||||
$this->error = 'Query failed: '.pg_last_error().' ('.$query_str.')';
|
||||
return false;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function fetchArray ( $toFetch ) {
|
||||
return pg_fetch_assoc($toFetch);
|
||||
}
|
||||
|
||||
public function fetchObject ( $toFetch ) {
|
||||
return pg_fetch_object($toFetch);
|
||||
}
|
||||
|
||||
public function fetchRow ( $toFetch ) {
|
||||
return pg_fetch_row($toFetch);
|
||||
}
|
||||
|
||||
public function numRows ( $toFetch ) {
|
||||
return pg_num_rows($toFetch);
|
||||
}
|
||||
|
||||
public function numQueries () {
|
||||
return $this->numQueries;
|
||||
}
|
||||
|
||||
public function close () {
|
||||
@pg_close($this->dbRes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue