Mittwoch, 11. Januar 2012 21:13
sorry I am a quite inexperienced programmer and my following question may be extremely stupid. Howeve, I have worked on this now for several hours without success and don't find my error.
The task is very simple, I just want to access data rows from my SQL database and get them as arrays into my PHP script. Here is an extract from the script:
$sql="SELECT TOP 1 * FROM TABLE";
The last statement returns " Resource id #4" so the query seems to work.resultfielddata=sqlsrv_field_metadata($result);
The last statement returns an array with correct metadata from the table. So the column information is correctly retrieved.$hasrows=sqlsrv_has_rows($result);
The last statement returns "1" so I assume that there are data-rows in the table (there should be one row of data).
So far so good.
In the next step I want to get the data from the first row of the resource as an array:
However this returns "FALSE" and print_r(sqlsrv_errors()); returns:
Array (  => Array (  => 01004 [SQLSTATE] => 01004  => 0 [code] => 0  => [Microsoft][SQL Server Native Client 10.0]String data, right truncation [message] => [Microsoft][SQL Server Native Client 10.0]String data, right truncation ) )
When I try to explore the $result array using
$row_count = sqlsrv_num_rows($result);
$row_count is false and the error array is:
Array (  => Array (  => IMSSP [SQLSTATE] => IMSSP  => -50 [code] => -50  => This function only works with statements that have static or keyset scrollable cursors. [message] => This function only works with statements that have static or keyset scrollable cursors. ) )
However, I defined the cursor at the beginning!!
So I am really stuck here and would be very glad if someone could help me out of this stupid problem. Why is the data not read into the array?
Thanks a lot in advance!!
Montag, 16. Januar 2012 16:36
Do you mind sharing the SQL query that you are executing? I can think of one situation where a cursor gets downgraded to a forward only cursor (depending on the query)...this forum thread has more details: http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/4a65fbe0-0c68-496b-bf72-2d3eec9f31a3/
Any information that will hep reproduce what you are seeing will help us get to the bottom of it quickly.
This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan
Dienstag, 17. Januar 2012 15:59Besitzer
please note that this is a German forum. If English is your preffered language, then please post on the English forums:
Raul Talmaciu, MICROSOFT
Bitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip „IT-Pros helfen IT-Pros“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.