修改。这个问题与SQLite有关,而不是MySQL。
请注意,以下查询返回字符串(3)“123”,而不是整数。
$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>