-1

好吧,我决定使用 PDO,因为我看到有人说它比 mysql 更好。

我有这段代码应该获取 uid、ticket_id 和事件表。

$query = $db->prepare("SELECT embedded_page.uid, embedded_page.ticket_id, embedded_page.event_table FROM embedded_page WHERE fbp_id = :fbp_id");
$query->bindValue(":fbp_id", $fbp_id, PDO::PARAM_INT);
$query->execute();

echo $compibot_user = $query->fetchObject()->uid;
echo $ticket_id = $query->fetchObject()->ticket_id;
echo $event_table = $query->fetchObject()->event_table;

查看代码,我回显了三个变量$compibot_user$ticket_id$event_table

我只得到的结果是“ 1 ”,这是$compibot_user的结果

$ticket_id 和 $event_table 没有回显任何内容。所以我一直想知道为什么它不起作用。这东西有什么解决办法吗?

4

3 回答 3

2

试试这个:

$sql="SELECT embedded_page.uid, embedded_page.ticket_id, embedded_page.event_table FROM embedded_page WHERE fbp_id = ?";        
$stmt=$db->prepare($sql) or die("Prepare Error");
$stmt->bindParam(1, $fbp_id);       
$stmt->execute();   

$result=$stmt->fetch(PDO::FETCH_ASSOC);

echo  $result['YOUR COLUMN NAME']; //example echo $result['ticket_id']; 

$stmt->closeCursor();
$stmt=NULL;
于 2013-03-23T15:55:02.227 回答
1

尝试这样的事情,也许:

$query = $db->prepare("SELECT embedded_page.uid, embedded_page.ticket_id, embedded_page.event_table FROM embedded_page WHERE fbp_id = :fbp_id");
$query->execute( array( 'fbp_id' => $fbp_id ) );
list ( $compibot_user, $ticket_id, $event_table ) = $query->fetch( PDO::FETCH_NUM );

print "$compibot_user, $ticket_id, $event_table\n";
于 2013-03-23T15:56:36.343 回答
0

最简单的解决方案:

$query = $db->prepare('SELECT `embedded_page`.`uid`, `embedded_page`.`ticket_id`, `embedded_page`.`event_table` FROM `embedded_page` WHERE `fbp_id` = ?');
$query->execute(array($fbp_id));

while(($row = $query->fetch(PDO::FETCH_ASSOC)) !== false) {
   echo $row['uid'], ', ', $row['ticket_id'], ', ', $row['event_table'];
}
于 2013-03-23T16:01:07.370 回答