7

EDIT. This question pertains to SQLite and not MySQL.

Note that the following query returns string(3) "123", and not an integer.

$db = new \PDO("sqlite:".__DIR__."/db/trends.db");
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

$stmt=$db->prepare('INSERT INTO trends(timestamp,data) VALUES (?,?)');
$stmt->execute([123,'Hello']);
$stmt=$db->prepare('SELECT timestamp FROM trends WHERE data=?');
$stmt->execute(['Hello']);
var_dump($stmt->fetchColumn()); // string(3) "123"
sqlite> .schema trends
CREATE TABLE trends (
  timestamp INTEGER,
  data TEXT NOT NULL,
  PRIMARY KEY (timestamp));
sqlite>
deceze
  • 510,633
  • 85
  • 743
  • 889
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • About the duplicates: This is about sqlite, not mysql. – jeroen Nov 14 '16 at 14:58
  • @jeroen Thanks for pointing that out. I thought I was clear, and searched beforehand and didn't find any similar questions. Is it just a PDO thing and not a MySQL or SQLite thing? Upon looking at the other questions, it is related to how PDO works with a given database, and each database can be different. As such, MySQL specific answers do not appear to be applicable. – user1032531 Nov 14 '16 at 15:03
  • So you can tell that it's rather a database API than PDO. – Your Common Sense Nov 14 '16 at 15:18
  • @YourCommonSense You mean the drivers that pertain to the API? Yes, I believe it is. – user1032531 Nov 14 '16 at 15:25
  • Hehe, another duplicate but it seems to be the one. = P – JazZ Nov 14 '16 at 15:32
  • @JazZ Finally, SQLite specific! Your linked answer indicates that it has nothing to do with the database, but only PDO. The other MySQL related answers, however, appear that it is based on the specific databases drivers. – user1032531 Nov 14 '16 at 15:41

0 Answers0