【问题标题】:MYSQL to PDO function Call to a member function query() on a non-objectMYSQL 到 PDO 函数 调用非对象上的成员函数 query()
【发布时间】:2015-04-12 11:14:14
【问题描述】:

mysql 的简单函数

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;

是我的示例页面是查询运行成功。

但我想编写简单的函数,它会在非对象上调用成员函数 query() 时出错

我的示例函数

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

但它的错误,我该怎么办?

【问题讨论】:

    标签: php mysql pdo


    【解决方案1】:

    使用全局

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

    【讨论】:

    • 感谢我知道此选项,但我的其他查询出现故障。示例我的主页,其他页面已损坏
    猜你喜欢
    • 1970-01-01
    • 2016-03-25
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 2011-03-21
    相关资源
    最近更新 更多