Question

I'm using MDB2 for prepared statements. I'm using the name-based example from the PEAR MDB2 site as a guide, and this is what I have so far:

        $q = '
            UPDATE 
                abc_news 
            SET 
                newstitle       = :newstitle,  
                categoryid      = :categoryid,  
                facilityid      = :facilityid,  
                user_id_mod     = :user_id_mod,  
                user_id_add     = :user_id_add,  
                display         = :display,  
                locked          = :locked,  
                datemodified    = NOW()
            WHERE 
                newsid          = :newsid
        ';

        $types = array(
            'text', 
            'integer',
            'integer',
            'integer',
            'integer',
            'integer',
            'integer',
            'integer',
        );

        $res = $mdb2_dbx->prepare($q, $types,MDB2_PREPARE_MANIP);

        $data = array(
            'newstitle'     => $n_newstitle, 
            'categoryid'    => $n_categoryid, 
            'facilityid'    => $n_facilityid, 
            'display'       => 1, 
            'locked'        => 1, 
            'user_id_add'   => $n_user_id_add, 
            'user_id_mod'   => $n_user_id_mod, 
            'newsid'        => $newsid, 
        );
        $affected_rows = $statment->execute($data);
        if (PEAR::isError($res))
            die('error');
        $statement->free();


        $q = '
            UPDATE 
                abc_news_text 
            SET 
                newstext        = :newstext  
            WHERE 
                newsid          = :newsid
        ';

        $types = array(
            'text', 
            'integer',
        );

        $statment = $mdb2_dbx->prepare($q, $types,MDB2_PREPARE_MANIP);

        $data = array(
            'newstext'      => $n_newstext, 
            'newsid'        => $newsid, 
        );
        $affected_rows = $statment->execute($data);
        if (PEAR::isError($res))
            die('error');                   

        $statement->free();

The first query works - an autoincremented $newsid is printed to the screen (it increases with each new submission).

Directly below, I get this error:

Fatal error: Call to undefined method MDB2_Error::execute() in news.php on line 160

Line 160 is the second $affected_rows = $statment->execute($data); line.

I'm freeing up the statement, and the syntax appears to be the same on both prepared statements.

What am I doing wrong here?

Was it helpful?

Solution

that is because You are getting an MDB2_ERROR object not a statement object. Your prepare() obviously didn't work and you are not checking for the success of the prepare() at all to know this.

Also, I am not sure how your first is working since you set the prepare result to $res variable instead of $statment. I also notice your variable name $statment has no e (not sure if this was a typo).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top