我写了如下代码
class helper{
public function __set($table,$type){
global $dbConfig;
$pardConfig=new PDO('mysql:host='.$dbConfig[0].';'.'dbname='.$dbConfig[1],$dbConfig[2],$dbConfig[3]);
$sql=$pardConfig->prepare("SELECT * FROM ".$table." WHERE menu_type=".$type);
$sql->execute();
$sql=$pardConfig->prepare("SELECT * FROM ".$table." WHERE id=".$type);
$sql->execute();
$result=$sql->fetchALL(PDO::FETCH_ASSOC);
var_dump($result);
}
}
$helper = new helper();
$helper->pard_menu = "main"; <<--- OUTPUT array(0) { }
$helper->pard_menu = 99;
/\_________________________________________ OUTPUT
array(1) { [0]=> array(4) { ["id"]=> string(2) "99" ["menu_title"]=> string(8) "leftmenu" ["menu_type"]=> string(4) "main" ["menu_description"]=> string(14) "left side menu" } }
如您所见,有一个名为“main”的菜单类型,但我没有从数据库中获取结果,但id正在获取结果。相同的数据库表。