本文介绍了pgsql 42601 PDO :: execute错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在$ pdo-> execute($ values)上遇到问题.

I have problems with $pdo->execute($values).

如果我使用不带$ values的$pdo->execute(),效果很好:

It works fine if I use $pdo->execute() without $values:

$dsn = sprintf('%s:host=%s;port=%s;dbname=%s', DB_TYPE, DB_HOST, DB_PORT, DB_NAME);
$pdo = new PDO($dsn, DB_USER, DB_PASS, array());
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = 'SELECT * FROM "user" ORDER BY id DESC LIMIT 50 OFFSET 0';
$stmt = $pdo->prepare(trim($sql));
$stmt->setFetchMode(PDO::FETCH_OBJ|PDO::FETCH_PROPS_LATE);
$stmt->execute();

echo "<pre>";
print_r($stmt->fetchAll());
echo "</pre>";

它工作正常,但是当我要添加值替换时:

It works fine, but when I want to add values replacement:

$dsn = sprintf('%s:host=%s;port=%s;dbname=%s', DB_TYPE, DB_HOST, DB_PORT, DB_NAME);
$pdo = new PDO($dsn, DB_USER, DB_PASS, array());
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = 'SELECT * FROM "user" ORDER BY ? ? LIMIT 50 OFFSET 0';
$values = array('id','DESC');

$stmt = $pdo->prepare(trim($sql));
$stmt->setFetchMode(PDO::FETCH_OBJ|PDO::FETCH_PROPS_LATE);
$stmt->execute($values);

echo "<pre>";
print_r($stmt->fetchAll());
echo "</pre>";

它不起作用.它返回:

推荐答案

如果order by子句中有多个列,则ORDER BY期望以逗号分隔的列列表

ORDER BY expects a comma-separated list of columns if there's more than one column in the order by clause

这篇关于pgsql 42601 PDO :: execute错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:16