aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Db/Mysqli.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-05-08 15:26:22 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-05-08 15:26:22 +0000
commitafc02bc1c3db9ffe8c9bf660c8aa08666752edfb (patch)
tree9a02b06b390dd0c1e796474b888e92c245473424 /h-source/Library/Db/Mysqli.php
parent7fdac301801bc44f6fdb343187413bdfd2d5366c (diff)
h-source:added new EasyGiant SVN version
Diffstat (limited to 'h-source/Library/Db/Mysqli.php')
-rw-r--r--h-source/Library/Db/Mysqli.php87
1 files changed, 61 insertions, 26 deletions
diff --git a/h-source/Library/Db/Mysqli.php b/h-source/Library/Db/Mysqli.php
index 09bb017..e6fdb15 100644
--- a/h-source/Library/Db/Mysqli.php
+++ b/h-source/Library/Db/Mysqli.php
@@ -101,21 +101,56 @@ class Db_Mysqli
{
return $this->db->errno;
}
-
- public function createSelectQuery($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=null,$using=null)
+
+ public function getJoinString($string)
{
- if (isset($where))
+ if (strstr($string,':'))
{
- $where='WHERE '.$where;
+ $tArray = explode(':',$string);
+ switch($tArray[0])
+ {
+ case 'i':
+ $jString = ' INNER JOIN ' . $tArray[1];
+ break;
+ case 'l':
+ $jString = ' LEFT JOIN ' . $tArray[1];
+ break;
+ case 'r':
+ $jString = ' RIGHT JOIN ' . $tArray[1];
+ break;
+ default:
+ $jString = ' INNER JOIN ' . $tArray[1];
+ break;
+ }
+ return $jString;
}
- if (isset($using))
+ else
+ {
+ return ' INNER JOIN '.$string;
+ }
+ }
+
+ public function createSelectQuery($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=array(),$using=array(),$join=array())
+ {
+ $maxValue = max(count($on),count($using),count($join));
+
+ $joinString = null;
+ for ($i=0; $i < $maxValue; $i++)
{
- $using ='USING ('.$using.')';
- $on = null;
+ $joinString .= isset($join[$i]) ? $this->getJoinString($join[$i]) : null;
+ if (isset($using[$i]))
+ {
+ $joinString .= ' USING ('.$using[$i].')';
+ }
+ else if (isset($on[$i]))
+ {
+ $joinString .= ' ON '.$on[$i];
+ }
}
- if (isset($on) and !isset($using))
+
+ if (isset($where))
{
- $on='ON '.$on;
+ $where='WHERE '.$where;
}
if (isset($order_by)) {
$order_by='ORDER BY '.$order_by;
@@ -127,13 +162,13 @@ class Db_Mysqli
$limit='LIMIT '.$limit;
}
- $query="SELECT $fields FROM $table $on $using $where $group_by $order_by $limit;";
+ $query="SELECT $fields FROM $table $joinString $where $group_by $order_by $limit;";
return $query;
}
- public function get_num_rows($table,$where=null,$group_by=null,$on=null,$using=null) {
+ public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) {
- $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using);
+ $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join);
$this->query = $query;
$ris = $this->db->query($query);
@@ -146,9 +181,9 @@ class Db_Mysqli
}
}
- public function getMath($func,$table,$field,$where=null,$group_by = null, $on=null,$using=null)
+ public function getMath($func,$table,$field,$where=null,$group_by = null, $on=array(),$using=array(),$join=array())
{
- $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using);
+ $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join);
$this->query = $query;
$result = $this->db->query($query);
@@ -165,32 +200,32 @@ class Db_Mysqli
}
//get the maximum value of the field $field of the table $table having the $where conditions
- public function getMax($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getMax($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('MAX',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('MAX',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the minimum value of the field $field of the table $table having the $where conditions
- public function getMin($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getMin($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('MIN',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('MIN',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the sum of the fields
- public function getSum($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getSum($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('SUM',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('SUM',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the average of the fields
- public function getAvg($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getAvg($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('AVG',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('AVG',$table,$field,$where,$group_by,$on,$using,$join);
}
- public function select($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=null,$using=null)
+ public function select($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=array(),$using=array(),$join=array())
{
- $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using);
+ $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join);
$this->query = $query;
$result = $this->db->query($query);
@@ -370,7 +405,7 @@ class Db_Mysqli
//function to check if exist the record having the field $id_name=$id_value
- public function recordExists($table,$fieldName,$fieldValue,$where = null,$groupBy=null,$on=null,$using=null)
+ public function recordExists($table,$fieldName,$fieldValue,$where = null,$groupBy=null,$on=array(),$using=array(),$join=array())
{
if (isset($where))
{
@@ -379,7 +414,7 @@ class Db_Mysqli
$fieldValue = '"'.$fieldValue.'"';
- $num = $this->get_num_rows($table,$fieldName.'='.$fieldValue.$where,$groupBy,$on,$using);
+ $num = $this->get_num_rows($table,$fieldName.'='.$fieldValue.$where,$groupBy,$on,$using,$join);
$res=($num>0) ? true : false;
return $res;