2015-04-12 90 views
-2

我与MySQL功能简单MYSQL到PDO函数调用一个成员函数查询()一个非对象

function sanatciver($id,$deger){ 
$result=mysql_query("select $deger from sanatci where sanatcino=$id"); 
$row=mysql_fetch_assoc($result); 
return $row["$deger"]; 
} 

与PDO

$records = $db->select('mp3no, sanatcino')->from('mp3')->where('sanatcino', '=', $sno)->where('onay', '=', 1)->orderBy('mp3no', 'desc')->getAll(); 
$adet=$db->count(); 
foreach($records as $record) { 
$mp3no    = $record->mp3no; 
$sanatcino    = $record->sanatcino; 

即时通讯新用户是我的样本页面查询成功运行。

,但我想是写简单的功能,它在非对象上做出错误调用一个成员函数查询()

我的样本函数

function sanatciver($id,$deger){ 
$result = $db->select('$deger')->from('sanatci')->where('sanatcino', '=', $id)->get(); 
$xx    = $result->$deger; 
return $xx; 
} 

但其制作错误,怎么能我做 ?

回答

-1

使用全局

function sanatciver($id,$deger){ 
    global $db; 
    $result = $db->select('$deger')->from('sanatci')->where('sanatcino', '=', $id)->get(); 
    $xx    = $result->$deger; 
    return $xx; 
    } 
+0

感谢我知道这个选择,但我的其他查询出毛病。在我的主页上打印其他页面已损坏 – sinan

相关问题