CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 17

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    47

    Exclamation 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_rsqlsrv_errors(), true));
    }
    sqlsrv_close$conn);
    ?>
    Last edited by PeejAvery; February 23rd, 2009 at 11:52 AM. Reason: Adde PHP tags.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #3
    Join Date
    Aug 2007
    Posts
    47

    Re: Catchable fatal error: Object of class DateTime could not be converted

    no, the field is named FechaPublicacion

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    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.

  5. #5
    Join Date
    Aug 2007
    Posts
    47

    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?

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    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
  •  





Click Here to Expand Forum to Full Width

Featured