Bug #40687 [Com]: ODBC+PHP+MSSQL generate error while executing multi query in one transaction
| From: | chris dot gralike at amis dot nl | Date: | Wed, 28 Jan 2015 13:10:42 +0000 |
| Subject: | Bug #40687 [Com]: ODBC+PHP+MSSQL generate error while executing multi query in one transaction | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190266@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=40687&edit=1
ID: 40687
Comment by: chris dot gralike at amis dot nl
Reported by: scottsdev at gmail dot com
Summary: ODBC+PHP+MSSQL generate error while executing multi
query in one transaction
Status: Not a bug
Type: Bug
Package: ODBC related
Operating System: Windows Server
PHP Version: 5.2.1
Block user comment: N
Private report: N
New Comment:
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,
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 00:15:14] scottsdev at gmail dot com
Hey Gr8,
Thanks Sir. I really did silly mistake by not providing argument in odbc_next_result. I passed
resource id. And it start to work.
Thanks for your Gr8 Help.
J. Scott
(Project Manager)
------------------------------------------------------------------------
[2007-03-02 21:58:56] fmk@php.net
There 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
}
------------------------------------------------------------------------
[2007-03-02 21:10:54] scottsdev at gmail dot com
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 1111111
------------------------------------------------------------------------
[2007-03-02 18:19:47] fmk@php.net
Your query returns multiple results. The first is for the insert statement and the second for the
select. Take a look at http://us3.php.net/odbc_next_result to see how to
move to the second result.
------------------------------------------------------------------------
[2007-03-02 00:43:53] 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]
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=40687&edit=1