Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

prepare statement no longer working

posted by darren 8 years ago

Hi,

My db prepare statement no longer works after upgrading?

public function enable($data)
	{
		$statement = $this->db->prepare("
			UPDATE comments
			SET enabled = %s
			WHERE id = %i",
				$enable, $id
		);
		
		$rows = array();
		
		foreach ($data as $id => $enable)
		{
			$result = $this->db->query($statement, $enable, $id);
			$rows[] = $result->countAffectedRows();
		}
		
		return count($rows);
	}

I get php error undefined variable: enable and undefined variable: id

Dont understand :(

Regards,

Darren

debugging results...

Query time was 0.00025320053100586 seconds for: SET SQL_MODE = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE' Query time was 0.00037980079650879 seconds for: SET NAMES 'utf8' Query time was 0.00023603439331055 seconds for: SET CHARACTER SET utf8 Query time was 0.0051820278167725 seconds for:

UPDATE comments SET enabled = %s WHERE id = %i Query time was 0.00050592422485352 seconds for:

UPDATE comments SET enabled = %s WHERE id = %i Query time was 0.00042200088500977 seconds for:

UPDATE comments SET enabled = %s WHERE id = %i Total query time: 0.0069789886474609 seconds

You don't set the values to $enable and $id, that's why you got those warnings.

Try

function enable($data, $enable, $id) { ... }
posted by jmtucu 8 years ago

Hi jmtucu,

thanks for that i realised what i had done... feel bloody silly :(

I changed it to...

public function enable($data)
    {
        $statement = $this->db->prepare("
            UPDATE comments
            SET enabled = %s
            WHERE id = %i"
        );
        
        $rows = array();
        
        foreach ($data as $id => $enable)
        {
            $result = $this->db->query($statement, $enable, $id);
            $rows[] = $result->countAffectedRows();
        }
        
        return count($rows);
    }

for some reason i was thinking about when i pass single params to the method and that somehow it was magically handled...

What was i thinking lol.

posted by darren 8 years ago