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 ++++-------------------------------------- 1 file changed, 15 insertions(+), 163 deletions(-) (limited to 'h-source/Library/Db/Mysql.php') 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) { -- cgit v1.2.3