Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

php - Prepare not defined

I have tried setting sessions which are stored in database.I have achieved this through implementing SessionHandlerInterface class.However i havenot used prepared statements before but now i want to implement prepared statements in order to make it sql injection proof.However , when i try the prepare method it shows me an error

Method Prepare not defined in Class

i even tried extending mysqli_stmt class which contains the methods for prepared statements.

This is the full code of session class that stores sessions inside the database.

http://codepad.org/KmLtO9ym

Part of the code to make the question much more clear

class SysSession implements SessionHandlerInterface
{
   private $link;

public function open($savePath, $sessionName)
{
    $link = new mysqli("localhost","root","","cakenbake");
    if($link){
        $this->link = $link;
        return true;
    }else{
        return false;
    }
}
public function close()
{
    mysqli_close($this->link);
    return true;
}
public function read($id)
{


    $result = mysqli_query($this->link,"SELECT Session_Data FROM Session WHERE Session_Id = '".$id."' AND Session_Expires > '".date('Y-m-d H:i:s')."'");

    /*$result=$this->link->prepare("Some query inside")
     * This shows up an error stating prepare method not found
     *
     */

    if($row = mysqli_fetch_assoc($result)){
        return $row['Session_Data'];
    }else{
        return "";
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem was with my IDE.It was the one who was showing errors.Restarted my IDE and it worked fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...