|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-02 00:43 UTC] scottsdev at gmail dot com
Description:
------------
Hello,
I used DSN to established connection with MSSQL using following Cursor.
Code is >>>
$conn = odbc_pconnect($dsn,$username,$password, SQL_CUR_USE_ODBC) or die("ERROR OCCUR WHILE CONNECTING TO THE SERVER");
I am getting following error when i tried to execute query like ...
$sql = "insert into <TBL_NAME> (col_1, col_2, col_3) values (val_1, val_2, val_3); select SCOPE_IDENTITY() as LastInsertedID";
$results = odbc_exec($conn, $sql) or die("<br><pre>Query fail: $query</pre>");
//////////////////////////////
if(!$results)
{
$this->error("<H2>No results!</H2>\n");
return false;
}else {
$data = array();
while ( $row = odbc_fetch_array($results))
{
$data = $row;
}
odbc_free_result($results);
$last_Id = $data['LastInsertedID'];
}
==================================================
So errors occurs
on this line: while ( $row = odbc_fetch_array($results))
Error is :
Warning: odbc_fetch_array() [function.odbc-fetch-array]: No tuples available at this result index in D:\inetpub\wwwroot\php\xyz\lib\xxxx.php on line 11111
So I really don't understand how to remove this error, and what to do so that such two query can be run at once and return the result.
J. Scott
[scottsdev at gmail dot com]
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 14:00:01 2025 UTC |
No Sir, Still it don't work. I put the if condition which check whether Next Result is found or not, and it come inside that clause and show error in fetch_array line. ================== $query = <<<END_SQL $query; select SCOPE_IDENTITY(); END_SQL; $results = odbc_exec($conn, $query) or die("<br><pre>Query fail: $query</pre>"); ////////////////////////////// if(!$results) { $this->error("<H2>No results!</H2>\n"); return false; }else { $data = array(); if (odbc_next_result){ while ( $row = odbc_fetch_array($results)) { ========================================= It still showing same error at ==> while ( $row = odbc_fetch_array($results)) Error: Warning: odbc_fetch_array() [function.odbc-fetch-array]: No tuples available at this result index in D:\inetpub\wwwroot\php\xyz\aaa.php on line 1111111There is no bug here. odbc_next_result() sjould be called with a odbc result resource as the parameter. That's the only way it can advnance the internal result pointer to the next result. You code should look like this: if (odbc_next_result($results)){ while ($row = odbc_fetch_array($results)) { // Do your stuff } } or // Move to the last result while (odbc_next_result($results)); while ($row = odbc_fetch_array($results)) { // Do your stuff }I found that counting fields that contain a logical 'NULL' example: SELECT COUNT([db].[table].[field_with_nulls]) as counted FROM [db].[table] WHERE {CONDITION} will sometimes trigger a No tuples at resultset warning. adding: AND [db].[table].[column_being_counted] is not null might solve the problem. My setup FreeDTS > unixODBC > PHP5.x Rgrds,