duanshan7261 2013-07-01 15:34
浏览 52
已采纳

PDO中的SELECT WHERE在PHP中准备

I create this table:

CREATE TABLE IF NOT EXISTS Users (Id INTEGER PRIMARY KEY, Username TEXT UNIQUE NOT NULL, Password TEXT NOT NULL, Time INTEGER UNIQUE NOT NULL, Timezone INTEGER NOT NULL, Active BOOLEAN NOT NULL);

and fill it with several rows. Then I'm trying to SELECT the 'Active' for a specific 'Username'. This is just one cell.

I want to do this with a prepared statement, but the problem is I can't even do it with a normal statement. This thing fails:

SELECT Active FROM Users WHERE Username "John"

This works though:

SELECT Active FROM Users WHERE Username LIKE "John%"

But I'm looking for an exact result. This one works too:

SELECT Active FROM Users WHERE Id=1

What am I missing?

EDIT

There is indeed a typo in my statement. A "=" is required (I'm leaving it as it is above). However this wasn't really the problem. I've traced it back in the use of prepared statements.

Whenever I store someting in the db using prepared statements, I can't search it using this:

SELECT Active FROM Users WHERE Username="John"

I'm very curious to see why this is happening but it belongs to another question.

  • 写回答

1条回答 默认 最新

  • dtdfl62844 2013-07-01 15:37
    关注
    SELECT Active FROM Users WHERE Username="John"
    

    Notice "="

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法