所有SQL调用函数,改为传入$sql而不是自行获取

This commit is contained in:
hyzboy 2016-09-03 21:49:23 +04:00
parent 5a64d688b6
commit 5a15cac736
3 changed files with 92 additions and 44 deletions

View File

@ -180,10 +180,8 @@
return file_get_contents('http://download.finance.yahoo.com/d/quotes.csv?s='.$source.$target.'=X&f=l1&e=.csv');
}
function get_service_hall_cash($currency)
function get_service_hall_cash($sql,$currency)
{
$sql=get_sql();
if(!$sql)return 0;
$sql_string='select Number from ServiceHall_Cash where SubCode="'.$_SESSION['service_hall'].'_'.$currency.'"';
@ -199,21 +197,16 @@
return $row[0];
}
function save_cash_to_service_hall($currency,$number)
function save_cash_to_service_hall($sql,$currency,$number)
{
$sql=get_sql();
if(!$sql)return(null);
if(!$sql)return;
$sql_result=$sql->query('INSERT INTO ServiceHall_Cash(SubCode,Code,Currency,Number) VALUES("'.$_SESSION['service_hall'].'_'.$currency.'","'.$_SESSION['service_hall'].'","'.$currency.'",'.$number.') ON DUPLICATE KEY UPDATE Number=Number+'.$number);
return;
return $sql->query('INSERT INTO ServiceHall_Cash(SubCode,Code,Currency,Number) VALUES("'.$_SESSION['service_hall'].'_'.$currency.'","'.$_SESSION['service_hall'].'","'.$currency.'",'.$number.') ON DUPLICATE KEY UPDATE Number=Number+'.$number);
}
function show_cash_from_service_hall($label)
function show_cash_from_service_hall($sql,$label)
{
$table=new UISQLTable($label,"ServiceHall_Cash",array("Currency","Number"),'Code="'.$_SESSION['service_hall'].'"');
$table=new UISQLTable($sql,$label,"ServiceHall_Cash",array("Currency","Number"),'Code="'.$_SESSION['service_hall'].'"');
$table->echo();
}

View File

@ -23,10 +23,69 @@
return $global_sql;
}
function get_field_list($table_name)
{
$sql=get_sql();
// class SQLSelect
// {
// private $field_list=null;
//
// private $where=null;
// private $limit_start=0;
// private $limit_count=0;
//
// public
// };//class SQLSelect
//
// class SQLTable
// {
// private $sql=null;
// private $table_name=null;
// private $insert_id=0;
//
// private $field_list=null;
//
// public function __construct($s,$tn)
// {
// $this->sql=$s;
// $this->table_name=$tn;
// }
//
// public function get_field_list()
// {
// if($field_list)
// return $field_list;
//
// $sql_result=$this->sql->query("DESC ".$this->table_name);
//
// if(!$sql_result)
// return null;
//
// $this->field_list=array();
// while ($row = $sql_result->fetch_object())
// $this->field_list[] = $row->Field;
//
// return $this->field_list;
// }
// };//class SQLTable
//
// class SQLConnect
// {
// private $sql=null;
//
// public function __construct()
// {
// $sql=get_sql();
// }
//
// public function OpenTable($table_name)
// {
// if(!$sql)
// return(null);
//
// return(new SQLTable($sql,$table));
// }
// };//class SQLConnect
function get_field_list($sql,$table_name)
{
if($sql==null)return null;
$sql_result=$sql->query("DESC ".$table_name);
@ -41,10 +100,8 @@
return $field_list;
}
function select_table($table_name,$field_list,$where,$start,$count)
function select_table($sql,$table_name,$field_list,$where,$start,$count)
{
$sql=get_sql();
if($sql==null)return;
$sql_string="SELECT";
@ -85,10 +142,8 @@
return $result;
}
function select_field($table_name,$field,$where)
function select_field($sql,$table_name,$field,$where)
{
$sql=get_sql();
if($sql==null)return;
$sql_string="SELECT ".$field." FROM ".$table_name." WHERE ".$where;
@ -107,17 +162,17 @@
/**
* 向一个表中插入数据使用array的kv模式表示字段和数据
*/
function sql_insert()//$table_name,$data_array)
function sql_insert()//$sql,$table_name,$data_array)
{
$sql=get_sql();
$sql=func_get_arg(0);
if($sql==null)return null;
$table_name=func_get_arg(0);
$data_array=func_get_arg(1);
$table_name=func_get_arg(1);
$data_array=func_get_arg(2);
if(func_num_args()==3)
$resultmode=func_get_arg(2);
if(func_num_args()==4)
$resultmode=func_get_arg(3);
else
$resultmode=MYSQLI_STORE_RESULT;
@ -148,19 +203,19 @@
/**
* 向一个表中插入数据字段数据来自于post
*/
function sql_insert_by_post()//$table_name,$field_array [,$resultmode=MYSQLI_STORE_RESULT])
function sql_insert_by_post()//$sql,$table_name,$field_array [,$resultmode=MYSQLI_STORE_RESULT])
{
$sql=get_sql();
$sql=func_get_arg(0);
if($sql==null)return null;
$data_array=array();
$table_name=func_get_arg(0);
$field_array=func_get_arg(1);
$table_name=func_get_arg(1);
$field_array=func_get_arg(2);
if(func_num_args()==3)
$resultmode=func_get_arg(2);
if(func_num_args()==4)
$resultmode=func_get_arg(3);
else
$resultmode=MYSQLI_STORE_RESULT;

View File

@ -90,29 +90,29 @@
private $bool_text=array();
private $enum_text=array();
public function __construct()//$sql_table_name,$field_list,$where,$start,$count)
public function __construct()//$sql,$sql_table_name,$field_list,$where,$start,$count)
{
$sql_table_name=func_get_arg(0);
$sql=func_get_arg(0);
$sql_table_name=func_get_arg(1);
if(func_num_args()>1)$field_list=func_get_arg(1);else $field_list=null;
if(func_num_args()>2)$where =func_get_arg(2);else $where=null;
if(func_num_args()>3)$start =func_get_arg(3);else $start=null;
if(func_num_args()>4)$count =func_get_arg(4);else $count=null;
if(func_num_args()>2)$field_list=func_get_arg(2);else $field_list=null;
if(func_num_args()>3)$where =func_get_arg(3);else $where=null;
if(func_num_args()>4)$start =func_get_arg(4);else $start=null;
if(func_num_args()>5)$count =func_get_arg(5);else $count=null;
if($field_list==null)
{
$field_list=get_field_list($sql_table_name);
$field_list=get_field_list($sql,$sql_table_name);
parent::set_fields($field_list);
$this->sql_result=select_table($sql_table_name,null,$where,$start,$count);
$this->sql_result=select_table($sql,$sql_table_name,null,$where,$start,$count);
}
else
{
parent::set_fields($field_list);
$this->sql_result=select_table($sql_table_name,$field_list,$where,$start,$count);
$this->sql_result=select_table($sql,$sql_table_name,$field_list,$where,$start,$count);
}
}