tags:

views:

189

answers:

1

Hi,

Does anyone here have some experience with this error?

Only If I use the WHERE clause, I get this error.

I use php PDO to get the results.

And this is my simple table

$sql = "CREATE TABLE samenvatting (
    stem_id INTEGER PRIMARY KEY AUTOINCREMENT,
    poll_id TEXT,
    stem_waarde_id TEXT,
    totaal INTEGER
    )";
    $crud->rawQuery($sql);

$poll_id = "somepoll";
$records = $crud->rawSelect('SELECT * FROM samenvatting WHERE poll_id='.$poll_id);

pdo abstract class

 public function conn()
        {
            isset($this->username);
            isset($this->password);
            if (!$this->db instanceof PDO)
            {
                $this->db = new PDO($this->dsn, $this->username, $this->password);
                $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            }
        }
 public function rawSelect($sql)
        {
            $this->conn();
            return $this->db->query($sql);
        }

Thanks, Richard

+1  A: 

It is treating "somepoll" as a column in the table. You need to quote it, since it is declared as text. Something like

$records = $crud->rawSelect(
    'SELECT * FROM samenvatting WHERE poll_id="' . $poll_id . '"'
);

perhaps?

MJB
THANKS, that might work.I haven´t try´d it yet doh.My solution was to use the pdo prepare and execute approach and not the standard pdo query function. I will remember this one.
Richard
You'd better use single quotes (') to specify literals in SQL, as double quotes are meant to escape names. However, double-quotes might still work with SQLite.
sereda