-
February 23rd, 2009, 11:25 AM
#1
Catchable fatal error: Object of class DateTime could not be converted
Hi...
i'm testing php + mssql 2005 compatibility, using some DLLs microsoft relased which are php_sqlsrv.dll and php_sqlsrv_ts.dll
i couldn't establish a connection with the first one, so i tried with the second one and it worked, i could run some queries perfectly until i got this error:
Catchable fatal error: Object of class DateTime could not be converted to string in C:\Archivos de programa\Apache Group\Apache2\htdocs\asea\conectamssql.php on line 16
i found out that when it reads a datetime or smalldatetime field it shows me that error, why? how could i make it work?
thanks in advance...
Here is the code:
PHP Code:
<?php $serverName = ("myServer"); $uid = ("userDB"); $pwd = ("myPWD"); $connectionInfo = array("UID" => $uid, "PWD" => $pwd,"Database"=>"someDB"); $conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) { $result = sqlsrv_query($conn,"select * from sometable"); if ($result) { while($row = sqlsrv_fetch_array($result)) { for ($i=0; $i < sqlsrv_num_fields($result); $i++) /*THIS IS LINE 16*/ echo $row[$i]; } } } else { echo "Connection could not be established.\n"; die( print_r( sqlsrv_errors(), true)); } sqlsrv_close( $conn); ?>
Last edited by PeejAvery; February 23rd, 2009 at 11:52 AM.
Reason: Adde PHP tags.
-
February 23rd, 2009, 11:56 AM
#2
Re: Catchable fatal error: Object of class DateTime could not be converted
Please remember to use code or php tags when posting code. Thanks!
Is your column actually named DateTime? Remember that it is a reserved word and cannot be used when outputting to an object.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 23rd, 2009, 11:59 AM
#3
Re: Catchable fatal error: Object of class DateTime could not be converted
no, the field is named FechaPublicacion
-
February 23rd, 2009, 01:54 PM
#4
Re: Catchable fatal error: Object of class DateTime could not be converted
Have you tried using the following instead?
Code:
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC)) {
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 23rd, 2009, 02:05 PM
#5
Re: Catchable fatal error: Object of class DateTime could not be converted
yes, i have... it does the same...
i've been reading that this php+sql 2005 driver is not the same as mssql.dll, it doesn't have num_rows(), data_seek(), etc...
why???
any suggestions?
-
February 23rd, 2009, 02:11 PM
#6
Re: Catchable fatal error: Object of class DateTime could not be converted
Well, the differences would come from who programmed them. However, there is nothing in your code that should be returning that error.
Try a single query that only the field that is DateTime. Echo that result to see if it is a data type conflict. PHP should automatically convert between data types.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|