Re: [sqlite] [PHP+PDO] SELECT fails when using prepare + placeholder

2019-10-21 Thread Winfried
Zakrzewski, Jakub wrote
> It's because `execute()` returns a boolean (as stated in the manual
> https://www.php.net/manual/en/pdostatement.execute.php ). `fetch()` must
> be called on `$query`

Thanks much!

=
$query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=? LIMIT 1");
$query->execute(array($mode));
$result = $query->fetch(PDO::FETCH_ASSOC);
if($result){
print($result["mode_txt"] . ""); 
} else
print("Bad!");
=



--
Sent from: http://sqlite.1065341.n5.nabble.com/
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] [PHP+PDO] SELECT fails when using prepare + placeholder

2019-10-21 Thread Zakrzewski, Jakub
It's because `execute()` returns a boolean (as stated in the manual 
https://www.php.net/manual/en/pdostatement.execute.php ).
`fetch()` must be called on `$query`


From: sqlite-users  on behalf of 
Winfried 
Sent: 21 October 2019 11:47
To: sqlite-users@mailinglists.sqlite.org
Subject: [sqlite] [PHP+PDO] SELECT fails when using prepare + placeholder

Hello,

I can't figure out why PHP isn't happy with the following query:

==
prepare('INSERT INTO mytable (date, home_id, mode_id) VALUES
(?, ?, ?)');
$query->execute(array($today,$home, $mode));

//CREATE TABLE mode (mode_id INTEGER, mode_txt TEXT);
//SELECT OK
//$query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=0 LIMIT
1");

//NOK !
$query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=? LIMIT 1");
$result=$query->execute(array($mode));
if ($result) {
//! Fatal error: Call to a member function fetch() on boolean in 
blah.php
$mode = $result->fetch(PDO::FETCH_COLUMN);
}

$dbh = null;
?>
==

Is it due to some incompatibility between SQLite's INTEGER and PDO?

Thank you.



--
Sent from: http://sqlite.1065341.n5.nabble.com/
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] [PHP+PDO] SELECT fails when using prepare + placeholder

2019-10-21 Thread Winfried
Hello,

I can't figure out why PHP isn't happy with the following query:

==
prepare('INSERT INTO mytable (date, home_id, mode_id) VALUES
(?, ?, ?)');
$query->execute(array($today,$home, $mode));

//CREATE TABLE mode (mode_id INTEGER, mode_txt TEXT);
//SELECT OK
//$query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=0 LIMIT
1");

//NOK !
$query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=? LIMIT 1");
$result=$query->execute(array($mode));
if ($result) {
//! Fatal error: Call to a member function fetch() on boolean in 
blah.php
$mode = $result->fetch(PDO::FETCH_COLUMN);
}   

$dbh = null;
?>
==

Is it due to some incompatibility between SQLite's INTEGER and PDO?

Thank you.



--
Sent from: http://sqlite.1065341.n5.nabble.com/
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users