【问题标题】:PHP fetch pdo with hyphen in column name [duplicate]PHP在列名中使用连字符获取pdo [重复]
【发布时间】:2014-01-03 23:57:50
【问题描述】:

所以我正在编写一个 php 项目,但我被困在数据库中表的列名中的连字符上。 我有以下代码:

 $results = $conn->query($sql)->fetchAll(PDO::FETCH_OBJ);
     foreach ($results as $row) { ?>
      <tr>
        <td><a href="#<?= $row->factuur-status ?>"><?= $row->factuur-status ?></a></td>
        <td><?= $row->verkoop-orderid ?></td>
      </tr>
<?php } ?>

现在显然由于列名中的连字符,这不起作用。 如何解决这个问题?

【问题讨论】:

  • 使用`转义连字符列名
  • 我不能在我写的代码中使用那些(``)。我已经试过了……

标签: php mysql sql database pdo


【解决方案1】:

我找到了,如果有人感兴趣的话:

<?= $row->{'factuur-status'} ?>

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 2011-07-22
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 2014-11-25
    • 2021-06-05
    相关资源
    最近更新 更多