HOR-4527
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
abe71a6ffe
commit
0d533e19d9
@@ -30,31 +30,27 @@
|
||||
* @package gulliver.system
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class database extends database_base
|
||||
{
|
||||
|
||||
public $iFetchType = MYSQL_ASSOC;
|
||||
public $iFetchType = MYSQLI_ASSOC;
|
||||
|
||||
/**
|
||||
* class database constructor
|
||||
* class database constructor.
|
||||
*
|
||||
* @param $sType adapter type
|
||||
* @param $sServer server
|
||||
* @param $sUser db user
|
||||
* @param $sPass db user password
|
||||
* @param $sDataBase Database name
|
||||
* @param string $sType adapter type
|
||||
* @param string $sServer server
|
||||
* @param string $sUser db user
|
||||
* @param string $sPass db user password
|
||||
* @param string $sDataBase Database name
|
||||
*/
|
||||
public function __construct ($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME)
|
||||
public function __construct($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME)
|
||||
{
|
||||
$this->sType = $sType;
|
||||
$this->sServer = $sServer;
|
||||
$this->sUser = $sUser;
|
||||
$this->sPass = $sPass;
|
||||
$this->sDataBase = $sDataBase;
|
||||
$this->oConnection = @mysql_connect( $sServer, $sUser, $sPass ) || null;
|
||||
$this->oConnection = mysqli_connect($sServer, $sUser, $sPass, $sDataBase) or die('Could not connect to database...');
|
||||
$this->sQuoteCharacter = '`';
|
||||
$this->nullString = 'null';
|
||||
}
|
||||
@@ -66,30 +62,29 @@ class database extends database_base
|
||||
* @param $aColumns array of columns
|
||||
* @return $sSql the sql sentence
|
||||
*/
|
||||
public function generateCreateTableSQL ($sTable, $aColumns)
|
||||
public function generateCreateTableSQL($sTable, $aColumns)
|
||||
{
|
||||
$sKeys = '';
|
||||
$sSQL = 'CREATE TABLE IF NOT EXISTS ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '(';
|
||||
|
||||
foreach ($aColumns as $sColumnName => $aParameters) {
|
||||
if ($sColumnName != 'INDEXES') {
|
||||
|
||||
if ($sColumnName != '' && isset( $aParameters['Type'] ) && $aParameters['Type'] != '') {
|
||||
if ($sColumnName != '' && isset($aParameters['Type']) && $aParameters['Type'] != '') {
|
||||
$sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type'];
|
||||
|
||||
if (isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') {
|
||||
if (isset($aParameters['Null']) && $aParameters['Null'] == 'YES') {
|
||||
$sSQL .= ' NULL';
|
||||
} else {
|
||||
$sSQL .= ' NOT NULL';
|
||||
$sSQL .= ' NOT NULL';
|
||||
}
|
||||
if (isset( $aParameters['AutoIncrement'] ) && $aParameters['AutoIncrement']) {
|
||||
if (isset($aParameters['AutoIncrement']) && $aParameters['AutoIncrement']) {
|
||||
$sSQL .= ' AUTO_INCREMENT PRIMARY KEY';
|
||||
}
|
||||
if (isset( $aParameters['Key'] ) && $aParameters['Key'] == 'PRI') {
|
||||
if (isset($aParameters['Key']) && $aParameters['Key'] == 'PRI') {
|
||||
$sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ',';
|
||||
}
|
||||
|
||||
if (isset( $aParameters['Default'] )) {
|
||||
if (isset($aParameters['Default'])) {
|
||||
$sSQL .= " DEFAULT '" . trim($aParameters['Default']) . "'";
|
||||
}
|
||||
|
||||
@@ -97,9 +92,9 @@ class database extends database_base
|
||||
}
|
||||
}
|
||||
}
|
||||
$sSQL = substr( $sSQL, 0, - 1 );
|
||||
$sSQL = substr($sSQL, 0, -1);
|
||||
if ($sKeys != '') {
|
||||
$sSQL .= ',PRIMARY KEY(' . substr( $sKeys, 0, - 1 ) . ')';
|
||||
$sSQL .= ',PRIMARY KEY(' . substr($sKeys, 0, -1) . ')';
|
||||
}
|
||||
$sSQL .= ')ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci' . $this->sEndLine;
|
||||
|
||||
@@ -112,7 +107,7 @@ class database extends database_base
|
||||
* @param $sTable table name
|
||||
* @return sql sentence string
|
||||
*/
|
||||
public function generateDropTableSQL ($sTable)
|
||||
public function generateDropTableSQL($sTable)
|
||||
{
|
||||
return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
||||
}
|
||||
@@ -123,7 +118,7 @@ class database extends database_base
|
||||
* @param $sTableOld old table name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateRenameTableSQL ($sTableOld)
|
||||
public function generateRenameTableSQL($sTableOld)
|
||||
{
|
||||
$sSQL = 'ALTER TABLE ' . $sTableOld . ' RENAME TO RBAC_' . $sTableOld;
|
||||
return $sSQL;
|
||||
@@ -136,7 +131,7 @@ class database extends database_base
|
||||
* @param $sColumn column name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateDropColumnSQL ($sTable, $sColumn)
|
||||
public function generateDropColumnSQL($sTable, $sColumn)
|
||||
{
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
||||
return $sSQL;
|
||||
@@ -187,7 +182,6 @@ class database extends database_base
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* generate an add column sentence
|
||||
*
|
||||
@@ -196,9 +190,9 @@ class database extends database_base
|
||||
* @param $aParameters parameters of field like typo or if it can be null
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateAddColumnSQL ($sTable, $sColumn, $aParameters)
|
||||
public function generateAddColumnSQL($sTable, $sColumn, $aParameters)
|
||||
{
|
||||
if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) {
|
||||
if (isset($aParameters['Type']) && isset($aParameters['Null'])) {
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ' ' . $aParameters['Type'];
|
||||
if ($aParameters['Null'] == 'YES') {
|
||||
$sSQL .= ' NULL';
|
||||
@@ -206,18 +200,18 @@ class database extends database_base
|
||||
$sSQL .= ' NOT NULL';
|
||||
}
|
||||
}
|
||||
if (isset( $aParameters['AutoIncrement'] ) && $aParameters['AutoIncrement']) {
|
||||
if (isset($aParameters['AutoIncrement']) && $aParameters['AutoIncrement']) {
|
||||
$sSQL .= ' AUTO_INCREMENT';
|
||||
}
|
||||
if (isset( $aParameters['PrimaryKey'] ) && $aParameters['PrimaryKey']) {
|
||||
if (isset($aParameters['PrimaryKey']) && $aParameters['PrimaryKey']) {
|
||||
$sSQL .= ' PRIMARY KEY';
|
||||
}
|
||||
if (isset( $aParameters['Unique'] ) && $aParameters['Unique']) {
|
||||
if (isset($aParameters['Unique']) && $aParameters['Unique']) {
|
||||
$sSQL .= ' UNIQUE';
|
||||
}
|
||||
|
||||
//we need to check the property AI
|
||||
if (isset( $aParameters['AI'] )) {
|
||||
if (isset($aParameters['AI'])) {
|
||||
if ($aParameters['AI'] == 1) {
|
||||
$sSQL .= ' AUTO_INCREMENT';
|
||||
} else {
|
||||
@@ -226,7 +220,7 @@ class database extends database_base
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isset( $aParameters['Default'] )) {
|
||||
if (isset($aParameters['Default'])) {
|
||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||
}
|
||||
}
|
||||
@@ -243,13 +237,13 @@ class database extends database_base
|
||||
* @param $sColumnNewName column new name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '')
|
||||
public function generateChangeColumnSQL($sTable, $sColumn, $aParameters, $sColumnNewName = '')
|
||||
{
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter;
|
||||
if (isset( $aParameters['Type'] )) {
|
||||
if (isset($aParameters['Type'])) {
|
||||
$sSQL .= ' ' . $aParameters['Type'];
|
||||
}
|
||||
if (isset( $aParameters['Null'] )) {
|
||||
if (isset($aParameters['Null'])) {
|
||||
if ($aParameters['Null'] == 'YES') {
|
||||
$sSQL .= ' NULL';
|
||||
} else {
|
||||
@@ -269,15 +263,15 @@ class database extends database_base
|
||||
// }
|
||||
//}
|
||||
//else {
|
||||
if (isset( $aParameters['Default'] )) {
|
||||
if (trim( $aParameters['Default'] ) == '' && $aParameters['Type'] == 'datetime') {
|
||||
if (isset($aParameters['Default'])) {
|
||||
if (trim($aParameters['Default']) == '' && $aParameters['Type'] == 'datetime') {
|
||||
//do nothing
|
||||
} else {
|
||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||
}
|
||||
//}
|
||||
}
|
||||
if (! isset( $aParameters['Default'] ) && isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') {
|
||||
if (!isset($aParameters['Default']) && isset($aParameters['Null']) && $aParameters['Null'] == 'YES') {
|
||||
$sSQL .= " DEFAULT NULL ";
|
||||
}
|
||||
//}
|
||||
@@ -291,11 +285,11 @@ class database extends database_base
|
||||
* @param $sTable table name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateGetPrimaryKeysSQL ($sTable)
|
||||
public function generateGetPrimaryKeysSQL($sTable)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
throw new Exception('The table name cannot be empty!');
|
||||
}
|
||||
return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine;
|
||||
} catch (Exception $oException) {
|
||||
@@ -309,11 +303,11 @@ class database extends database_base
|
||||
* @param $sTable table name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateDropPrimaryKeysSQL ($sTable)
|
||||
public function generateDropPrimaryKeysSQL($sTable)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
throw new Exception('The table name cannot be empty!');
|
||||
}
|
||||
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP PRIMARY KEY' . $this->sEndLine;
|
||||
} catch (Exception $oException) {
|
||||
@@ -328,17 +322,17 @@ class database extends database_base
|
||||
* @param $aPrimaryKeys array of primary keys
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys)
|
||||
public function generateAddPrimaryKeysSQL($sTable, $aPrimaryKeys)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
throw new Exception('The table name cannot be empty!');
|
||||
}
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY (';
|
||||
foreach ($aPrimaryKeys as $sKey) {
|
||||
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ',';
|
||||
}
|
||||
$sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine;
|
||||
$sSQL = substr($sSQL, 0, -1) . ')' . $this->sEndLine;
|
||||
return $sSQL;
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
@@ -352,14 +346,14 @@ class database extends database_base
|
||||
* @param $sIndexName index name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateDropKeySQL ($sTable, $sIndexName)
|
||||
public function generateDropKeySQL($sTable, $sIndexName)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
throw new Exception('The table name cannot be empty!');
|
||||
}
|
||||
if ($sIndexName == '') {
|
||||
throw new Exception( 'The column name cannot be empty!' );
|
||||
throw new Exception('The column name cannot be empty!');
|
||||
}
|
||||
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine;
|
||||
} catch (Exception $oException) {
|
||||
@@ -376,7 +370,7 @@ class database extends database_base
|
||||
* @return sql sentence
|
||||
*/
|
||||
|
||||
public function generateAddKeysSQL ($sTable, $indexName, $aKeys)
|
||||
public function generateAddKeysSQL($sTable, $indexName, $aKeys)
|
||||
{
|
||||
try {
|
||||
$indexType = 'INDEX';
|
||||
@@ -388,7 +382,7 @@ class database extends database_base
|
||||
foreach ($aKeys as $sKey) {
|
||||
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', ';
|
||||
}
|
||||
$sSQL = substr( $sSQL, 0, - 2 );
|
||||
$sSQL = substr($sSQL, 0, -2);
|
||||
$sSQL .= ')' . $this->sEndLine;
|
||||
return $sSQL;
|
||||
} catch (Exception $oException) {
|
||||
@@ -401,7 +395,7 @@ class database extends database_base
|
||||
*
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateShowTablesSQL ()
|
||||
public function generateShowTablesSQL()
|
||||
{
|
||||
return 'SHOW TABLES' . $this->sEndLine;
|
||||
}
|
||||
@@ -411,7 +405,7 @@ class database extends database_base
|
||||
*
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateShowTablesLikeSQL ($sTable)
|
||||
public function generateShowTablesLikeSQL($sTable)
|
||||
{
|
||||
return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine;
|
||||
}
|
||||
@@ -422,11 +416,11 @@ class database extends database_base
|
||||
* @param $sTable table name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateDescTableSQL ($sTable)
|
||||
public function generateDescTableSQL($sTable)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
throw new Exception('The table name cannot be empty!');
|
||||
}
|
||||
return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
||||
} catch (Exception $oException) {
|
||||
@@ -440,7 +434,7 @@ class database extends database_base
|
||||
* @param $sTable table name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateTableIndexSQL ($sTable)
|
||||
public function generateTableIndexSQL($sTable)
|
||||
{
|
||||
return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine;
|
||||
//return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " WHERE Key_name <> 'PRIMARY'" . $this->sEndLine;
|
||||
@@ -451,12 +445,14 @@ class database extends database_base
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function isConnected ()
|
||||
public function isConnected()
|
||||
{
|
||||
if (! $this->oConnection) {
|
||||
return false;
|
||||
$connect = false;
|
||||
if ($this->oConnection !== false) {
|
||||
$this->executeQuery('USE ' . $this->sDataBase);
|
||||
$connect = true;
|
||||
}
|
||||
return $this->executeQuery( 'USE ' . $this->sDataBase );
|
||||
return $connect;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,34 +461,34 @@ class database extends database_base
|
||||
* @param $sQuery sql query string
|
||||
* @return void
|
||||
*/
|
||||
public function logQuery ($sQuery)
|
||||
public function logQuery($sQuery)
|
||||
{
|
||||
try {
|
||||
$found = false;
|
||||
if (substr( $sQuery, 0, 6 ) == 'SELECT') {
|
||||
if (substr($sQuery, 0, 6) == 'SELECT') {
|
||||
$found = true;
|
||||
}
|
||||
if (substr( $sQuery, 0, 4 ) == 'SHOW') {
|
||||
if (substr($sQuery, 0, 4) == 'SHOW') {
|
||||
$found = true;
|
||||
}
|
||||
if (substr( $sQuery, 0, 4 ) == 'DESC') {
|
||||
if (substr($sQuery, 0, 4) == 'DESC') {
|
||||
$found = true;
|
||||
}
|
||||
if (substr( $sQuery, 0, 4 ) == 'USE ') {
|
||||
if (substr($sQuery, 0, 4) == 'USE ') {
|
||||
$found = true;
|
||||
}
|
||||
if (! $found) {
|
||||
if (!$found) {
|
||||
$logDir = PATH_DATA . 'log';
|
||||
if (! file_exists( $logDir )) {
|
||||
if (! mkdir( $logDir )) {
|
||||
if (!file_exists($logDir)) {
|
||||
if (!mkdir($logDir)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$logFile = "$logDir/query.log";
|
||||
$fp = fopen( $logFile, 'a+' );
|
||||
$fp = fopen($logFile, 'a+');
|
||||
if ($fp !== false) {
|
||||
fwrite( $fp, date( "Y-m-d H:i:s" ) . " " . $this->sDataBase . " " . $sQuery . "\n" );
|
||||
fclose( $fp );
|
||||
fwrite($fp, date("Y-m-d H:i:s") . " " . $this->sDataBase . " " . $sQuery . "\n");
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
} catch (Exception $oException) {
|
||||
@@ -505,20 +501,21 @@ class database extends database_base
|
||||
* @param $sQuery table name
|
||||
* @return void
|
||||
*/
|
||||
public function executeQuery ($sQuery)
|
||||
public function executeQuery($sQuery)
|
||||
{
|
||||
$this->logQuery( $sQuery );
|
||||
$this->logQuery($sQuery);
|
||||
|
||||
try {
|
||||
if ($this->oConnection) {
|
||||
@mysql_select_db( $this->sDataBase );
|
||||
|
||||
return @mysql_query( $sQuery );
|
||||
mysqli_select_db($this->oConnection, $this->sDataBase);
|
||||
$result = mysqli_query($this->oConnection, $sQuery);
|
||||
mysqli_use_result($this->oConnection);
|
||||
return $result;
|
||||
} else {
|
||||
throw new Exception( 'invalid connection to database ' . $this->sDataBase );
|
||||
throw new Exception('invalid connection to database ' . $this->sDataBase);
|
||||
}
|
||||
} catch (Exception $oException) {
|
||||
$this->logQuery( $oException->getMessage() );
|
||||
$this->logQuery($oException->getMessage());
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
@@ -529,20 +526,24 @@ class database extends database_base
|
||||
* @param $oDataset
|
||||
* @return the number of rows
|
||||
*/
|
||||
public function countResults ($oDataset)
|
||||
public function countResults($oDataset)
|
||||
{
|
||||
return @mysql_num_rows( $oDataset );
|
||||
return mysqli_num_rows($oDataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* count an array of the registry from a dataset
|
||||
*
|
||||
* @param $oDataset
|
||||
* @param $dataSet
|
||||
* @return the registry
|
||||
*/
|
||||
public function getRegistry ($oDataset)
|
||||
public function getRegistry($dataSet)
|
||||
{
|
||||
return @mysql_fetch_array( $oDataset, $this->iFetchType );
|
||||
$response = null;
|
||||
if ($dataSet !== false) {
|
||||
$response = mysqli_fetch_array($dataSet, $this->iFetchType);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -550,80 +551,80 @@ class database extends database_base
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function close ()
|
||||
public function close()
|
||||
{
|
||||
@mysql_close( $this->oConnection );
|
||||
mysqli_close($this->oConnection);
|
||||
}
|
||||
|
||||
public function generateInsertSQL ($table, $data)
|
||||
public function generateInsertSQL($table, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$values = array ();
|
||||
$fields = array();
|
||||
$values = array();
|
||||
foreach ($data as $field) {
|
||||
$fields[] = $field['field'];
|
||||
if (! is_null( $field['value'] )) {
|
||||
if (!is_null($field['value'])) {
|
||||
switch ($field['type']) {
|
||||
case 'text':
|
||||
case 'date':
|
||||
$values[] = "'" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||
$values[] = "'" . mysqli_real_escape_string($this->oConnection, $field['value']) . "'";
|
||||
break;
|
||||
case 'int':
|
||||
default:
|
||||
$values[] = mysql_real_escape_string( $field['value'] );
|
||||
$values[] = mysqli_real_escape_string($this->oConnection, $field['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$values[] = $this->nullString;
|
||||
}
|
||||
}
|
||||
$fields = array_map( array ($this,'putQuotes'
|
||||
), $fields );
|
||||
$sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) );
|
||||
$fields = array_map(array($this, 'putQuotes'
|
||||
), $fields);
|
||||
$sql = sprintf("INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes($table), implode(', ', $fields), implode(', ', $values));
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function generateUpdateSQL ($table, $keys, $data)
|
||||
public function generateUpdateSQL($table, $keys, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$where = array ();
|
||||
$fields = array();
|
||||
$where = array();
|
||||
foreach ($data as $field) {
|
||||
if (! is_null( $field['value'] )) {
|
||||
if (!is_null($field['value'])) {
|
||||
switch ($field['type']) {
|
||||
case 'text':
|
||||
case 'date':
|
||||
$fields[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||
$fields[] = $this->putQuotes($field['field']) . " = '" . mysqli_real_escape_string($this->oConnection, $field['value']) . "'";
|
||||
break;
|
||||
case 'int':
|
||||
default:
|
||||
$fields[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||
$fields[] = $this->putQuotes($field['field']) . " = " . mysqli_real_escape_string($this->oConnection, $field['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$values[] = $this->nullString;
|
||||
}
|
||||
if (in_array( $field['field'], $keys )) {
|
||||
$where[] = $fields[count( $fields ) - 1];
|
||||
if (in_array($field['field'], $keys)) {
|
||||
$where[] = $fields[count($fields) - 1];
|
||||
}
|
||||
}
|
||||
$sql = sprintf( "UPDATE %s SET %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $where ) );
|
||||
$sql = sprintf("UPDATE %s SET %s WHERE %s", $this->putQuotes($table), implode(', ', $fields), implode(', ', $where));
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function generateDeleteSQL ($table, $keys, $data)
|
||||
public function generateDeleteSQL($table, $keys, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$where = array ();
|
||||
$fields = array();
|
||||
$where = array();
|
||||
foreach ($data as $field) {
|
||||
if (in_array( $field['field'], $keys )) {
|
||||
if (! is_null( $field['value'] )) {
|
||||
if (in_array($field['field'], $keys)) {
|
||||
if (!is_null($field['value'])) {
|
||||
switch ($field['type']) {
|
||||
case 'text':
|
||||
case 'date':
|
||||
$where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||
$where[] = $this->putQuotes($field['field']) . " = '" . mysqli_real_escape_string($this->oConnection, $field['value']) . "'";
|
||||
break;
|
||||
case 'int':
|
||||
default:
|
||||
$where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||
$where[] = $this->putQuotes($field['field']) . " = " . mysqli_real_escape_string($this->oConnection, $field['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -631,25 +632,25 @@ class database extends database_base
|
||||
}
|
||||
}
|
||||
}
|
||||
$sql = sprintf( "DELETE FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) );
|
||||
$sql = sprintf("DELETE FROM %s WHERE %s", $this->putQuotes($table), implode(', ', $where));
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function generateSelectSQL ($table, $keys, $data)
|
||||
public function generateSelectSQL($table, $keys, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$where = array ();
|
||||
$fields = array();
|
||||
$where = array();
|
||||
foreach ($data as $field) {
|
||||
if (in_array( $field['field'], $keys )) {
|
||||
if (! is_null( $field['value'] )) {
|
||||
if (in_array($field['field'], $keys)) {
|
||||
if (!is_null($field['value'])) {
|
||||
switch ($field['type']) {
|
||||
case 'text':
|
||||
case 'date':
|
||||
$where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||
$where[] = $this->putQuotes($field['field']) . " = '" . mysqli_real_escape_string($this->oConnection, $field['value']) . "'";
|
||||
break;
|
||||
case 'int':
|
||||
default:
|
||||
$where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||
$where[] = $this->putQuotes($field['field']) . " = " . mysqli_real_escape_string($this->oConnection, $field['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -657,11 +658,11 @@ class database extends database_base
|
||||
}
|
||||
}
|
||||
}
|
||||
$sql = sprintf( "SELECT * FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) );
|
||||
$sql = sprintf("SELECT * FROM %s WHERE %s", $this->putQuotes($table), implode(', ', $where));
|
||||
return $sql;
|
||||
}
|
||||
|
||||
private function putQuotes ($element)
|
||||
private function putQuotes($element)
|
||||
{
|
||||
return $this->sQuoteCharacter . $element . $this->sQuoteCharacter;
|
||||
}
|
||||
@@ -676,14 +677,14 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sConcat
|
||||
*/
|
||||
public function concatString ()
|
||||
public function concatString()
|
||||
{
|
||||
$nums = func_num_args();
|
||||
$vars = func_get_args();
|
||||
|
||||
$sConcat = " CONCAT(";
|
||||
for ($i = 0; $i < $nums; $i ++) {
|
||||
if (isset( $vars[$i] )) {
|
||||
for ($i = 0; $i < $nums; $i++) {
|
||||
if (isset($vars[$i])) {
|
||||
$sConcat .= $vars[$i];
|
||||
if (($i + 1) < $nums) {
|
||||
$sConcat .= ", ";
|
||||
@@ -693,7 +694,6 @@ class database extends database_base
|
||||
$sConcat .= ")";
|
||||
|
||||
return $sConcat;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -709,11 +709,10 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sCompare
|
||||
*/
|
||||
public function getCaseWhen ($compareValue, $trueResult, $falseResult)
|
||||
public function getCaseWhen($compareValue, $trueResult, $falseResult)
|
||||
{
|
||||
$sCompare = "IF(" . $compareValue . ", " . $trueResult . ", " . $falseResult . ") ";
|
||||
return $sCompare;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,7 +723,7 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sql
|
||||
*/
|
||||
public function createTableObjectPermission ()
|
||||
public function createTableObjectPermission()
|
||||
{
|
||||
$sql = "CREATE TABLE IF NOT EXISTS `OBJECT_PERMISSION` (
|
||||
`OP_UID` varchar(32) NOT NULL,
|
||||
@@ -754,9 +753,8 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sql
|
||||
*/
|
||||
public function getSelectReport4 ()
|
||||
public function getSelectReport4()
|
||||
{
|
||||
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
|
||||
@@ -772,7 +770,6 @@ class database extends database_base
|
||||
GROUP BY " . $sqlGroupBy;
|
||||
|
||||
return $sql;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -783,7 +780,7 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sql
|
||||
*/
|
||||
public function getSelectReport4Filter ($var)
|
||||
public function getSelectReport4Filter($var)
|
||||
{
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
@@ -800,7 +797,6 @@ class database extends database_base
|
||||
GROUP BY " . $sqlGroupBy;
|
||||
|
||||
return $sql;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -811,7 +807,7 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sql
|
||||
*/
|
||||
public function getSelectReport5 ()
|
||||
public function getSelectReport5()
|
||||
{
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
@@ -828,7 +824,6 @@ class database extends database_base
|
||||
GROUP BY " . $sqlGroupBy;
|
||||
|
||||
return $sql;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -839,9 +834,8 @@ class database extends database_base
|
||||
*
|
||||
* @return string $sql
|
||||
*/
|
||||
public function getSelectReport5Filter ($var)
|
||||
public function getSelectReport5Filter($var)
|
||||
{
|
||||
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
|
||||
@@ -863,41 +857,39 @@ class database extends database_base
|
||||
* query functions for class class.net.php
|
||||
*
|
||||
*/
|
||||
public function getServerVersion ($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename)
|
||||
public function getServerVersion($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename)
|
||||
{
|
||||
|
||||
if ($link = @mysql_connect( $dbIP, $dbUser, $dbPasswd )) {
|
||||
$v = @mysql_get_server_info();
|
||||
if ($link = mysqli_connect($dbIP, $dbUser, $dbPasswd, $dbSourcename)) {
|
||||
$v = mysqli_get_server_info($link);
|
||||
} else {
|
||||
throw new Exception( @mysql_error( $link ) );
|
||||
throw new Exception(mysqli_error($link));
|
||||
}
|
||||
return (isset( $v )) ? $v : 'none';
|
||||
|
||||
return (isset($v)) ? $v : 'none';
|
||||
}
|
||||
|
||||
/*
|
||||
* query functions for class class.net.php, class.reportTables.php
|
||||
*
|
||||
*/
|
||||
public function getDropTable ($sTableName)
|
||||
public function getDropTable($sTableName)
|
||||
{
|
||||
$sql = 'DROP TABLE IF EXISTS `' . $sTableName . '`';
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function getTableDescription ($sTableName)
|
||||
public function getTableDescription($sTableName)
|
||||
{
|
||||
$sql = "DESC " . $sTableName;
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function getFieldNull ()
|
||||
public function getFieldNull()
|
||||
{
|
||||
$fieldName = "Null";
|
||||
return $fieldName;
|
||||
}
|
||||
|
||||
public function getValidate ($validate)
|
||||
public function getValidate($validate)
|
||||
{
|
||||
$oValidate = $validate;
|
||||
return $oValidate;
|
||||
@@ -907,14 +899,14 @@ class database extends database_base
|
||||
* Determines whether a table exists
|
||||
* It is part of class.reportTables.php
|
||||
*/
|
||||
public function reportTableExist ()
|
||||
public function reportTableExist()
|
||||
{
|
||||
$filter = new InputFilter();
|
||||
$DB_NAME = $filter->validateInput(DB_NAME);
|
||||
$bExists = true;
|
||||
$oConnection = mysql_connect( DB_HOST, DB_USER, DB_PASS );
|
||||
mysql_select_db( $DB_NAME );
|
||||
$oDataset = mysql_query( 'SELECT COUNT(*) FROM REPORT_TABLE' ) || ($bExists = false);
|
||||
$oConnection = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
|
||||
mysqli_select_db($oConnection, $DB_NAME);
|
||||
$oDataset = mysqli_query($oConnection, 'SELECT COUNT(*) FROM REPORT_TABLE') || ($bExists = false);
|
||||
|
||||
return $bExists;
|
||||
}
|
||||
@@ -922,7 +914,7 @@ class database extends database_base
|
||||
/**
|
||||
* It is part of class.pagedTable.php
|
||||
*/
|
||||
public function getLimitRenderTable ($nCurrentPage, $nRowsPerPage)
|
||||
public function getLimitRenderTable($nCurrentPage, $nRowsPerPage)
|
||||
{
|
||||
$sql = ' LIMIT ' . (($nCurrentPage - 1) * $nRowsPerPage) . ', ' . $nRowsPerPage;
|
||||
return $sql;
|
||||
@@ -930,32 +922,23 @@ class database extends database_base
|
||||
|
||||
/**
|
||||
* Determining the existence of a table
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function tableExists ($tableName, $database)
|
||||
public function tableExists($tableName, $database)
|
||||
{
|
||||
@mysql_select_db( $database );
|
||||
$tables = array ();
|
||||
$tablesResult = mysql_query( "SHOW TABLES FROM $database;" );
|
||||
while ($row = @mysql_fetch_row( $tablesResult )) {
|
||||
mysqli_select_db($this->oConnection, $database);
|
||||
$tables = array();
|
||||
$tablesResult = mysqli_query($this->oConnection, "SHOW TABLES FROM $database;");
|
||||
while ($row = mysqli_fetch_row($tablesResult)) {
|
||||
$tables[] = $row[0];
|
||||
}
|
||||
if (in_array( $tableName, $tables )) {
|
||||
if (in_array($tableName, $tables)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determining the existence of a table (Depricated)
|
||||
*/
|
||||
// function tableExists ($table, $db) {
|
||||
// $tables = mysql_list_tables ($db);
|
||||
// while (list ($temp) = @mysql_fetch_array ($tables)) {
|
||||
// if ($temp == $table) {
|
||||
// return TRUE;
|
||||
// }
|
||||
// }
|
||||
// return FALSE;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user