如何将此函数更改为另一个函数。我不想使用get_result使用bind_result&fetch()或store_result()代替get_result
我在网上搜索,但找不到可以帮助我的答案。
public function Select($Table_Name, $Conditions='' ,$Array_Conditions_Limit=NULL , $OrderBy='', $Limit='', $Selected_Fields='*')
{
$Query = "SELECT ".$Selected_Fields." FROM ".$Table_Name;
if(!empty($Conditions))
$Query .= " WHERE ".$Conditions;
if(!empty($OrderBy))
$Query .= " ORDER BY ".$OrderBy;
if(!empty($Limit))
$Query .= " LIMIT ".$Limit;
$Statment = $this->ConnectionResult->prepare($Query);
if(isset($Array_Conditions_Limit) )
{
$Statment = $this->DynamicBindVariables($Statment, $Array_Conditions_Limit);
$Statment->execute();
return $Statment->get_result();
}
else
$Statment->execute();
return $Statment->get_result();
}
这里也可以动态绑定变量
private function DynamicBindVariables($Statment, $Params)
{
if (is_array($Params) && $Params != NULL)
{
// Generate the Type String (eg: 'issisd')
$Types = '';
foreach($Params as $Param)
{
$Types .= $this->GetType($Param);
}
// Add the Type String as the first Parameter
$Bind_names[] = $Types;
// Loop thru the given Parameters
for ($i=0; $i<count($Params);$i++)
{
$Bind_name = 'bind' . $i;
// Add the Parameter to the variable
$$Bind_name = $Params[$i];
// Associate the Variable as an Element in the Array
$Bind_names[] = &$$Bind_name;
}
// Call the Function bind_param with dynamic Parameters
call_user_func_array(array($Statment,'bind_param'), $Bind_names);
}
elseif(isset($Params) && !empty($Params))
{
$Types = '';
$Types .= $this->GetType($Params);
$Statment->bind_param($Types ,$Params);
}
return $Statment;
}
我使用的返回值如下
:
所有的$myresult =Select('post','post_category=?' ,2 );
$row = $myresul2->fetch_object()
我会回答,但这个无用的'select()'函数排斥我。我不知道为什么这个[不方便且完全无法使用]的方法对PHP用户非常有吸引力。 –
你能告诉我更多关于它的信息吗?为什么没用? – majid
由于出色的SQL语言几乎像自然英语一样读取,所以您制作了一个丑陋的科学怪人,没有人可以读取(颠倒读取),并且可以让您只运行愚蠢的查询,从而使其无法处理任何复杂的查询。所有这些都可以为你节省三个字的输入 –