PHP - 只使用MySQL获取一个元素

时间:2022-01-04 03:36:52

I use PHP and MySQL in order to access to my database.

我使用PHP和MySQL来访问我的数据库。

My table is like this :

我的桌子是这样的:

Table(id INT PK, title VARCHAR(255))

I'm using PDO and I'd like to get only the id :

我正在使用PDO,我只想获得id:

SELECT id FROM Table WHERE title='stackover';

But PDO returns an array.

但是PDO返回一个数组。

1 个解决方案

#1


Use $statement->fetchColumn() to get the id as $id.

使用$ statement-> fetchColumn()将id作为$ id。

#1


Use $statement->fetchColumn() to get the id as $id.

使用$ statement-> fetchColumn()将id作为$ id。