/** * Include the adodb database abstraction */ require_once "[[softpath]]/adodb/adodb.inc.php"; /** @noinspection PhpUndefinedClassInspection */
/** * Class to represent the database access for the document management * * @category DMS * @package LetoDMS_Core * @author Markus Westphal, Malcolm Cowe, Matteo Lucarelli, Uwe Steinmann <uwe@steinmann.cx> * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, 2010 Uwe Steinmann * @version Release: @package_version@ */ class LetoDMS_Core_DatabaseAccess { var $_debug; var $_driver; var $_hostname; var $_database; var $_user; var $_passw; var $_conn; var $_connected; var $_ttreviewid; var $_ttapproveid; var $_ttstatid; var $_ttcontentid; var $_intransaction;
/* Backup functions */
/** * Return list of all database tables * * This function is used to retrieve a list of database tables for backup * * @return array list of table names */ function TableList() { return $this->_conn->MetaTables("TABLES"); }
/** * Constructor of LetoDMS_Core_DatabaseAccess * * Sets all database parameters but does not connect. * * @param string $driver the database type e.g. mysql, sqlite * @param string $hostname host of database server * @param string $user name of user having access to database * @param string $passw password of user * @param bool|string $database name of database */ function __construct($driver, $hostname, $user, $passw, $database = false) { $this->_driver = $driver; $this->_hostname = $hostname; $this->_database = $database; $this->_user = $user; $this->_passw = $passw; $this->_connected = false; $this->_intransaction = 0; // $tt*****id is a hack to ensure that we do not try to create the // temporary table twice during a single connection. Can be fixed by // using Views (MySQL 5.0 onward) instead of temporary tables. // CREATE ... IF NOT EXISTS cannot be used because it has the // unpleasant side-effect of performing the insert again even if the // table already exists. // // See createTemporaryTable() method for implementation. $this->_ttreviewid = false; $this->_ttapproveid = false; $this->_ttstatid = false; $this->_ttcontentid = false; $this->_debug = false; }
/** * Connect to database * * @return boolean true if connection could be established, otherwise false */ function connect() { /* {{{ */ $this->_conn = ADONewConnection($this->_driver); if ($this->_database) $this->_conn->Connect($this->_hostname, $this->_user, $this->_passw, $this->_database); else $this->_conn->Connect($this->_hostname, $this->_user, $this->_passw);
/** * Make sure a database connection exisits * * This function checks for a database connection. If it does not exists * it will reconnect. * * @return boolean true if connection is established, otherwise false */ function ensureConnected() { /* {{{ */ if (!$this->_connected) return $this->connect(); else return true; } /* }}} */
/** * Execute SQL query and return result * * Call this function only with sql query which return data records. * * @param string $queryStr sql query * @return array|boolean data if query could be executed otherwise false */ function getResultArray($queryStr) { /* {{{ */ /** @noinspection PhpUnusedLocalVariableInspection */ $resArr = array();
/** * Execute SQL query * * Call this function only with sql query which do not return data records. * * @param string $queryStr sql query * @return bool true if query could be executed otherwise false * @internal param bool $silent not used anymore. This was used when this method * still issued an error message */ function getResult($queryStr) { /* {{{ */ $res = $this->_conn->Execute($queryStr); if(!$res) { if($this->_debug) echo "error: ".$queryStr."<br />"; }
return $res; } /* }}} */
/** * Return the id of the last instert record * * @return integer id used in last autoincrement */ function getInsertID() { /* {{{ */ return $this->_conn->Insert_ID(); } /* }}} */