0

Let's say, I I have this query in my postgresql.

SELECT * FROM logs WHERE user_id = 8328 AND punchin::date = '2013-06-11';

it returns successful.

But when I implent it in PHP:

$sql = "SELECT * FROM logs WHERE user_id = $user_id AND punchin::date = $date";
$record = pg_query($sql);
$row = pg_fetch_array($record);

var_dump($row) //false

what happened? how come I cant get the data?

4

1 回答 1

1

尝试改变

$sql = "SELECT * FROM logs WHERE user_id = $user_id AND punchin::date = $date";

$sql = "SELECT * FROM logs WHERE user_id = '$user_id' AND DATE(punchin) = '$date'";

更好的是使用参数

$sql = "SELECT * FROM logs WHERE user_id = $1 AND CAST(punchin AS DATE) = $2";
$result = pg_query_params($sql, array($user_id, $date));
于 2013-06-14T05:15:27.797 回答