From 3ff03dc4f0a72432b34c00da620272cf011e4ddd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Jul 2021 14:17:20 +1000 Subject: Publishing h-node.org code. - this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers) --- h-source/Library/Db/Mysql.php | 178 +++------------------------ h-source/Library/Db/Mysqli.php | 264 ++++------------------------------------- 2 files changed, 41 insertions(+), 401 deletions(-) (limited to 'h-source/Library/Db') diff --git a/h-source/Library/Db/Mysql.php b/h-source/Library/Db/Mysql.php index e0dcfe0..4561a1b 100755 --- a/h-source/Library/Db/Mysql.php +++ b/h-source/Library/Db/Mysql.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,34 +24,16 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to manage the database //singleton! -class Db_Mysql -{ - - private $autocommit = true; - private $transactionBatchSize = 100; - - public $transactionBatch = array(); +class Db_Mysql { public $query = null; //the last query executed - public $queries = array(); //array containing all the queries executed - public $charsetError = true; //true: non eccor occurred during the modification of the connection charset, false: one error occurred public $charset = null; //the charset of the client connection private static $instance = null; //instance of this class private $dblink; - - private $charTypes = array('varchar','char'); - private $textTypes = array('tinytext','text','mediumtext','longtext'); - private $integerTypes = array('tinyint','smallint','int','mediumint','bigint'); - private $floatTypes = array('real','float','double'); - private $dateTypes = array('date'); - private $enumTypes = array('enum'); - private $decimalTypes = array('decimal'); - private $uniqueIndexStrings = array('UNI'); - - private $fieldsType = array(); + private $fieldsType = array('tinyint','smallint','int','mediumint','bigint','float','double'); /** *connect to the database @@ -69,8 +51,7 @@ class Db_Mysql private function __construct($host,$user,$pwd,$db_name) { - $this->fieldsType = array_merge($this->integerTypes, $this->floatTypes); - + $this->dblink = mysql_connect($host,$user,$pwd); if ($this->dblink === FALSE) { @@ -97,46 +78,7 @@ class Db_Mysql return self::$instance; } - public function getUniqueIndexStrings() - { - return $this->uniqueIndexStrings; - } - - public function getTextTypes() - { - return $this->textTypes; - } - - public function getDecimalTypes() - { - return $this->decimalTypes; - } - - public function getEnumTypes() - { - return $this->enumTypes; - } - - public function getCharTypes() - { - return $this->charTypes; - } - - public function getIntegerTypes() - { - return $this->integerTypes; - } - - public function getFloatTypes() - { - return $this->floatTypes; - } - - public function getDateTypes() - { - return $this->dateTypes; - } - + //close the connection public function disconnect() { @@ -221,29 +163,16 @@ class Db_Mysql public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) { - $select = isset($group_by) ? "*" : 'count(*) as number'; - - $query = $this->createSelectQuery($table,$select,$where,$group_by,null,null,$on,$using,$join); + $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join); $this->query=$query; - $this->queries[] = $query; $ris = mysql_query($query); if ($ris) { - - if (isset($group_by)) - { - $num_rows = mysql_num_rows($ris); - } - else - { - $row = mysql_fetch_array($ris); - $num_rows = $row['number']; - } - - return (int)$num_rows; + $num_rows = mysql_num_rows($ris); + return $num_rows; } else { - return 0; + return false; } } @@ -253,8 +182,6 @@ class Db_Mysql $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = mysql_query($query); if ($result) { @@ -296,8 +223,6 @@ class Db_Mysql $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = mysql_query($query); return $this->getData($result); } @@ -334,73 +259,31 @@ class Db_Mysql } else { - return array(); + return false; } } - - private function getFieldsFeature($feature, $table, $fields, $full = false, $associative = false) + //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) + public function getTypes($table, $fields) { $query = "DESCRIBE $table;"; $result = mysql_query($query); $temp = array(); while ($row = mysql_fetch_assoc($result)) { - if ($full) - { - $temp[$row['Field']] = $row[$feature]; - } - else - { - $e = explode('(',$row[$feature]); - $temp[$row['Field']] = strcmp($feature,"Type") === 0 ? strtolower(reset($e)) : reset($e); - } + $temp[$row['Field']] = reset(explode('(',$row['Type'])); } - $this->queries[] = $query; - - //return all fields types - if ($fields === "*") - { - $fields = implode(",",array_keys($temp)); - } - $types = array(); $fields = explode(',',$fields); for ($i = 0; $i < count($fields); $i++) { if (!array_key_exists($fields[$i],$temp)) return false; - - if ($associative) - { - $types[$fields[$i]] = $temp[$fields[$i]]; - } - else - { - $types[] = $temp[$fields[$i]]; - } + $types[] = $temp[$fields[$i]]; } return $types; } - //return an array containing all the keys of the fields (indicated in $fields) of a table (indicated in $table) - public function getKeys($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Key', $table, $fields, $full, $associative); - } - - //return an array containing all the default values of the fields (indicated in $fields) of a table (indicated in $table) - public function getDefaultValues($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Default', $table, $fields, $full, $associative); - } - - //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) - public function getTypes($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Type', $table, $fields, $full, $associative); - } - public function insert($table,$fields,$values) { #$table is a string @@ -428,8 +311,6 @@ class Db_Mysql $values = implode(',',$values); $query="INSERT INTO $table ($fields) VALUES ($values);"; $this->query = $query; - $this->queries[] = $query; - $ris = mysql_query($query); #check the result @@ -438,34 +319,12 @@ class Db_Mysql } else { return false; } - + } else { return false; } } - //set the autocommit attribute - public function setAutocommit($value) - { - } - - //set the transactionBatchSize attribute - public function setTransactionBatchSize($size) - { - } - - //commit a batch of queries - //$batch: array of queries - public function commitBatch($batch) - { - } - - //commit the transaction - public function commitTransaction() - { - return false; - } - // Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). public function lastId() { @@ -507,8 +366,6 @@ class Db_Mysql $str=implode(',',$str); $query="UPDATE $table SET $str $where;"; $this->query=$query; - $this->queries[] = $query; - $ris = mysql_query($query); #check the result @@ -517,7 +374,6 @@ class Db_Mysql } else { return false; } - } else { return false; } @@ -533,8 +389,6 @@ class Db_Mysql // } $query="DELETE FROM $table $where;"; $this->query=$query; - $this->queries[] = $query; - $ris = mysql_query($query); #check the result @@ -568,8 +422,6 @@ class Db_Mysql public function query($query) { $this->query = $query; - $this->queries[] = $query; - $result = mysql_query($query); if ($result === false) { diff --git a/h-source/Library/Db/Mysqli.php b/h-source/Library/Db/Mysqli.php index bd3ce1c..df57a54 100644 --- a/h-source/Library/Db/Mysqli.php +++ b/h-source/Library/Db/Mysqli.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -27,31 +27,14 @@ if (!defined('EG')) die('Direct access not allowed!'); class Db_Mysqli { - private $autocommit = true; - private $transactionBatchSize = 100; - - public $transactionBatch = array(); - public $query = null; //the last query executed - public $queries = array(); //array containing all the queries executed - public $charsetError = true; //true: non eccor occurred during the modification of the connection charset, false: one error occurred public $charset = null; //the charset of the client connection private static $instance = null; //instance of this class private $db; - - private $charTypes = array('varchar','char'); - private $textTypes = array('tinytext','text','mediumtext','longtext'); - private $integerTypes = array('tinyint','smallint','int','mediumint','bigint'); - private $floatTypes = array('real','float','double'); - private $dateTypes = array('date'); - private $enumTypes = array('enum'); - private $decimalTypes = array('decimal'); - private $uniqueIndexStrings = array('UNI'); - - private $fieldsType = array(); + private $fieldsType = array('tinyint','smallint','int','mediumint','bigint','float','double'); //PHP-Mysql charset translation table private $charsetTranslationTable = array( @@ -70,8 +53,7 @@ class Db_Mysqli private function __construct($host,$user,$pwd,$db_name) { - $this->fieldsType = array_merge($this->integerTypes, $this->floatTypes); - + $this->db = new mysqli($host,$user,$pwd,$db_name); if (mysqli_connect_error()) @@ -103,46 +85,7 @@ class Db_Mysqli return self::$instance; } - public function getUniqueIndexStrings() - { - return $this->uniqueIndexStrings; - } - - public function getTextTypes() - { - return $this->textTypes; - } - - public function getDecimalTypes() - { - return $this->decimalTypes; - } - - public function getEnumTypes() - { - return $this->enumTypes; - } - - public function getCharTypes() - { - return $this->charTypes; - } - - public function getIntegerTypes() - { - return $this->integerTypes; - } - - public function getFloatTypes() - { - return $this->floatTypes; - } - - public function getDateTypes() - { - return $this->dateTypes; - } - + //close the connection public function disconnect() { @@ -227,30 +170,16 @@ class Db_Mysqli public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) { - $select = isset($group_by) ? "*" : 'count(*) as number'; - - $query = $this->createSelectQuery($table,$select,$where,$group_by,null,null,$on,$using,$join); + $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $ris = $this->db->query($query); if ($ris) { - - if (isset($group_by)) - { - $num_rows = $ris->num_rows; - } - else - { - $row = $ris->fetch_array(); - $num_rows = $row['number']; - } - + $num_rows = $ris->num_rows; $ris->close(); - return (int)$num_rows; + return $num_rows; } else { - return 0; + return false; } } @@ -259,8 +188,6 @@ class Db_Mysqli $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = $this->db->query($query); if ($result) { @@ -303,8 +230,6 @@ class Db_Mysqli $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = $this->db->query($query); return $this->getData($result); } @@ -337,85 +262,44 @@ class Db_Mysqli $result->close(); return $data; } else { - return array(); + return false; } } - private function getFieldsFeature($feature, $table, $fields, $full = false, $associative = false ) + //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) + public function getTypes($table, $fields) { $query = "DESCRIBE $table;"; $result = $this->db->query($query); $temp = array(); while ($row = $result->fetch_assoc()) { - if ($full) - { - $temp[$row['Field']] = $row[$feature]; - } - else - { - $e = explode('(',$row[$feature]); - $temp[$row['Field']] = strcmp($feature,"Type") === 0 ? strtolower(reset($e)) : reset($e); - } + $temp[$row['Field']] = reset(explode('(',$row['Type'])); } $result->close(); - $this->queries[] = $query; - - //return all fields types - if ($fields === "*") - { - $fields = implode(",",array_keys($temp)); - } - $types = array(); $fields = explode(',',$fields); for ($i = 0; $i < count($fields); $i++) { if (!array_key_exists($fields[$i],$temp)) return false; - - if ($associative) - { - $types[$fields[$i]] = $temp[$fields[$i]]; - } - else - { - $types[] = $temp[$fields[$i]]; - } + $types[] = $temp[$fields[$i]]; } return $types; } - //return an array containing all the keys of the fields (indicated in $fields) of a table (indicated in $table) - public function getKeys($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Key', $table, $fields, $full, $associative); - } - - //return an array containing all the default values of the fields (indicated in $fields) of a table (indicated in $table) - public function getDefaultValues($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Default', $table, $fields, $full, $associative); - } - - //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) - public function getTypes($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Type', $table, $fields, $full, $associative); - } - public function insert($table,$fields,$values) { + #$table is a string #$fields has to be a string with comma as separator: name1,name2,... #$values has to be an array - $values = array_values($values); if (strcmp($fields,'') !== 0) { //get the type of the fields $types = $this->getTypes($table,$fields); if (!$types) return false; - + for($i = 0; $i < count($values); $i++) { if (!in_array($types[$i],$this->fieldsType)) @@ -431,103 +315,21 @@ class Db_Mysqli $values = implode(',',$values); $query="INSERT INTO $table ($fields) VALUES ($values);"; $this->query=$query; - $this->queries[] = $query; - if ($this->autocommit) - { - $ris = $this->db->query($query); + $ris = $this->db->query($query); - #check the result - if ($ris) { - return true; - } else { - return false; - } - } - else - { - $this->transactionBatch[] = $query; + #check the result + if ($ris) { return true; + } else { + return false; } + } else { return false; } } - //set the autocommit attribute - public function setAutocommit($value) - { - if ($value === true or $value === false) - { - $this->autocommit = $value; - $this->db->autocommit($value); - } - else - { - $this->autocommit = true; - $this->db->autocommit(true); - } - } - - //set the transactionBatchSize attribute - public function setTransactionBatchSize($size) - { - $this->transactionBatchSize = abs($size); - } - - //commit a batch of queries - //$batch: array of queries - public function commitBatch($batch) - { - foreach ($batch as $sql) - { - $this->db->query($sql); - } - - if (!$this->autocommit and $this->db->commit()) - { - return true; - } - else - { - return false; - } - } - - //commit the transaction - public function commitTransaction() - { - $returnArray = array(); - - if (!$this->autocommit) - { - if (count($this->transactionBatch) > 0) - { - if ($this->transactionBatchSize === 0) - { - $returnArray[] = $this->commitBatch($this->transactionBatch); - } - else - { - $batchArray = array_chunk($this->transactionBatch, $this->transactionBatchSize); - - foreach ($batchArray as $batch) - { - $returnArray[] = $this->commitBatch($batch); - } - } - } - } - - if (count(array_filter($returnArray)) === count($returnArray)) - { - $this->transactionBatch = array(); - return true; - } - - return false; - } - // Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). public function lastId() { @@ -569,23 +371,13 @@ class Db_Mysqli $str=implode(',',$str); $query="UPDATE $table SET $str $where;"; $this->query=$query; - $this->queries[] = $query; - - if ($this->autocommit) - { - $ris = $this->db->query($query); + $ris = $this->db->query($query); - #check the result - if ($ris) { - return true; - } else { - return false; - } - } - else - { - $this->transactionBatch[] = $query; + #check the result + if ($ris) { return true; + } else { + return false; } } else { return false; @@ -602,8 +394,6 @@ class Db_Mysqli // } $query="DELETE FROM $table $where;"; $this->query=$query; - $this->queries[] = $query; - $ris = $this->db->query($query); #check the result @@ -638,8 +428,6 @@ class Db_Mysqli public function query($query) { $this->query = $query; - $this->queries[] = $query; - $result = $this->db->query($query); if ($result === true) { -- cgit v1.2.3