Php 选择单行
我正在将论坛帖子存储到数据库中,需要选择添加的最后一行 我有一个id字段,它在Php 选择单行,php,pdo,Php,Pdo,我正在将论坛帖子存储到数据库中,需要选择添加的最后一行 我有一个id字段,它在自动递增上,所以我需要做的是选择id是最高的,主题=1 这是我到目前为止得到的,没有任何回音 $statementt56 = $db->prepare("SELECT * FROM topics WHERE topic_cat = '1' ORDER BY topic_id DESC LIMIT 1 "); $battle_gett56 = $statementt56->fetch(); echo
自动递增
上,所以我需要做的是选择id是最高的,主题=1
这是我到目前为止得到的,没有任何回音
$statementt56 = $db->prepare("SELECT * FROM topics WHERE topic_cat = '1' ORDER BY topic_id DESC LIMIT 1 ");
$battle_gett56 = $statementt56->fetch();
echo $battle_gett56['topic_subject'] ;
我做错了什么?我已使用此代码修复了此问题
$statementt = $db->prepare("SELECT * FROM topics WHERE topic_cat = '1' ORDER BY topic_id DESC LIMIT 1 ");
$statementt->execute(array());
$battle_gett = $statementt->fetch(); // Use fetchAll() if you want all results, or just iterate over the statement, since it implements Iterator
echo $battle_gett['topic_subject'] ;
现在一切都很完美我尝试过使用execute,但出现了一个错误,说execute不是一个函数。。。