我有一个简单的sql select查询(类似于下面的),在使用占位符时返回零结果:
$sql='SELECT * FROM table
WHERE column1=?
AND column2=?;';
$sth = $dbh->prepare($sql);
$sth->execute(array(1,2));
然而,当我对sql进行硬编码时,我收到了结果:
$sql='SELECT * FROM table
WHERE column1=1
AND column2=2;';
$sth = $dbh->prepare($sql);
$sth->execute();
有谁可以解释为什么我的占位符不起作用?
修改 准备声明成功。以下是完整查询:
$sql='SELECT * FROM calendar
LEFT JOIN class_schedule
ON calendar.week=class_schedule.week
AND calendar.class_day=class_schedule.class_day
AND calendar.class_time=class_schedule.class_time
LEFT JOIN class_enrolledIn
ON class_enrolledIn.class=class_schedule.class
LEFT JOIN users
ON class_enrolledIn.u_id=users.id
WHERE calendar.week=?
AND calendar.class_day=?
AND u_id IS NOT NULL;';
答案 0 :(得分:0)
我已经修好了。但仍然不能100%确定为什么整数不能用作枚举字段的输入,因为它适用于硬编码的sql。
基本上与enums和int
有关