douwei1408 2014-03-26 08:33
浏览 30
已采纳

PHP / SQL,具有Assoc值的异常行为

I am making an SQL query through PHP, and I need to retrieve a field called shipdate carrying a Datetime object.

Now,

$databk=sqlsrv_fetch_array( $qbk, SQLSRV_FETCH_ASSOC);

If I write

print_r($databk);

following is the output:

Array ( [prc_iva] => 22.00 [clientCode] => 000003 [artCode] => LEODRG-1104 [quantity] => 3 [shipdate] => DateTime Object ( [date] => 2014-04-23 00:00:00 [timezone_type] => 3 [timezone] => Europe/Belgrade ) [cod_um] => PZ [cod_art] => LEODRG-1104 [des_articolo] => SCATOLE C/FIORI PORCE [cod_immagine_small] => LEODRG-1104PIC.jpg [prz_listino] => 2.750000)

As you can see, we have the shipdate field here.

But, if I write

echo $databk['shipdate'];

the output is null/(blank string).

Now, here's why it gets creepy:

I used exactly the same query on another page. To be honest, I just copy-pasted the query so even the variable names are same. It works on the other page, but here is the problem on this page.

I need to resolve this as soon as possible. Thanks for your help, if any, in advance.

Ask for any additional information, if required. I shall be quick

EDIT2: Apparently, I couldn't echo date. But here's the new question. Why could I do it on another page. In fact, I still do. Why does it work at one place and not at the other?

  • 写回答

1条回答 默认 最新

  • du4010 2014-03-26 08:38
    关注

    You stored in datebase DateTime object. Not a clear date stamp. You can try with this:

    $date = $databk['shipdate'];
    echo $date->format('Y-m-d');
    

    I preffer and suggest to store in datebase only clear date. If you need help please show insert query with variables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛