简体   繁体   中英

PHP/SQL, Anomalous behaviour with Assoc value

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM