Hi,
I am using PHP 4.2.3 and Sybase 12.0
I want to insert records in multiple tables in a database.
I also want to use transactions so that I can rollback in case there
was a problem.
I tried the following code, but I can not figure out how to retrieve
the "status" from the batch.
If I run the code in sql, it works fine. If I run it in PHP, it again
works fine. But I cannot retrieve the "status". And I get the
following error message in the php log file.
=== START OF CODE ====
$sql = <<< SQL
declare @sys_code smallint
select @sys_code = isnull(max(code),0) from t_system
select @sys_code = @sys_code + 1
begin tran
insert into t_system values (@sys_code, "$sys_name", "$sys_fullname",
"$descr", $multi, $days_taken, $sys_group)
if (@@error > 0)
begin
rollback tran
select ret_status = -1
end
else
begin
commit tran
select ret_status = 0
end
SQL;
$dbh = sybase_connect($db_server, $db_login, $db_password,
$db_charset);
$res = sybase_query($sql, $dbh);
$rc = sybase_result($res,0,0);
if ($rc == 0) {
echo "The record was updated." ;
} else {
echo "Problem while updating database. The return code was : $rc" ;
}
=== END OF CODE ===
=== START OF ERROR MESSAGE ===
[18-Mar-2004 15:09:20] PHP Warning: sybase_result(): supplied
argument is not a valid Sybase result resource in ...
=== END OF ERROR MESSAGE === 3 3428
"Ashish" <ou****@india.com> wrote in message
news:dd**************************@posting.google.c om... Hi,
I am using PHP 4.2.3 and Sybase 12.0
I want to insert records in multiple tables in a database. I also want to use transactions so that I can rollback in case there was a problem.
I tried the following code, but I can not figure out how to retrieve the "status" from the batch.
If I run the code in sql, it works fine. If I run it in PHP, it again works fine. But I cannot retrieve the "status". And I get the following error message in the php log file. === START OF CODE ====
$sql = <<< SQL
declare @sys_code smallint
select @sys_code = isnull(max(code),0) from t_system select @sys_code = @sys_code + 1
begin tran
insert into t_system values (@sys_code, "$sys_name", "$sys_fullname", "$descr", $multi, $days_taken, $sys_group)
if (@@error > 0) begin rollback tran select ret_status = -1 end else begin commit tran select ret_status = 0 end
SQL;
$dbh = sybase_connect($db_server, $db_login, $db_password, $db_charset); $res = sybase_query($sql, $dbh); $rc = sybase_result($res,0,0); if ($rc == 0) { echo "The record was updated." ; } else { echo "Problem while updating database. The return code was : $rc" ; }
=== END OF CODE ===
=== START OF ERROR MESSAGE ===
[18-Mar-2004 15:09:20] PHP Warning: sybase_result(): supplied argument is not a valid Sybase result resource in ...
=== END OF ERROR MESSAGE ===
Since you are doing an insert, you do not get a result set back.
You need to remove the sybase_result() line.
Here is what I use for an update test, insert should be the same
<?
function update($query) {
if (!$sybResult = @sybase_query($query,$this->conn)) {
error_log ("Sybase Error : - Query failed ");
exit();
}
return true;
}
?>
> Since you are doing an insert, you do not get a result set back. You need to remove the sybase_result() line.
Thanks for your reply.
I actually want to get a result set back. A 1 column 1 row result set.
So, in my code, I say :
if (@@error > 0)
begin
rollback tran
select -1
end
else
begin
commit
select 0
end
This is after the Insert. So, I should get a -1 or a 0 back.
When I run this same query from isql, I do get a 1 col 1 row result set back.
On Thu, 18 Mar 2004 17:17:46 -0800, Ashish wrote: Since you are doing an insert, you do not get a result set back. You need to remove the sybase_result() line.
Thanks for your reply.
I actually want to get a result set back. A 1 column 1 row result set. So, in my code, I say :
if (@@error > 0) begin rollback tran select -1 end else begin commit select 0 end
This is after the Insert. So, I should get a -1 or a 0 back. When I run this same query from isql, I do get a 1 col 1 row result set back.
I think the problem is related to the fact that PHP doesn't really support
multiple result sets. I haven't looked closely at the code recently, but I
know that it was something that bothered me with PHP's implementation of
Sybase connectivity.
Michael
--
Michael Peppler Data Migrations, Inc. mp******@peppler.org http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.peppler.org/resume.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Don |
last post by:
Hi,
I am moving from Sybase to Oracle and I used to be able to do update
statement like this in Sybase:
UPDATE TABLE1
SET T1.field1 = T2.field2
FROM TABLE1 T1, TABLE2 T2
WHERE T1.field2...
|
by: Dave |
last post by:
I have 2 tables, one with names, and another with addresses, joined by their
CIVICID number (unique to the ADDRESSINFO table) in Oracle.
I need to update a field in the NAMEINFO table for a...
|
by: Lauren Quantrell |
last post by:
In VBA, I constructed the following to update all records in
tblmyTable with each records in tblmyTableTEMP having the same
UniqueID:
UPDATE
tblMyTable RIGHT JOIN tblMyTableTEMP ON...
|
by: Jan van Veldhuizen |
last post by:
The UPDATE table FROM syntax is not supported by Oracle.
I am looking for a syntax that is understood by both Oracle and SqlServer.
Example:
Table1:
id name city ...
|
by: Shawn |
last post by:
Hi.
I have a stored procedure in my Sybase 11.9, but I get an error when I try
to update a row. This happends when I have more than 126 chars in one of my
parameters. The parameter is declared...
|
by: Metal2You |
last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that
accesses a Sybase database back end. We're using Sybase SQL Anywhere
9.0.2.3228. I have installed and registered the Sybase...
|
by: Alex Murphy |
last post by:
As title, Thanks
|
by: Richard |
last post by:
Hello!
I have this piece of SQL code:
UPDATE a
SET Field1 = c.Field1
FROM a
INNER JOIN b ON a.GUID1 = b.GUID1
INNER JOIN c ON b.GUID2 = c.GUID2
WHERE c.Type = 1
|
by: =?ISO-8859-1?Q?S=E9bastien_Sabl=E9?= |
last post by:
WHAT IS IT:
The Sybase module provides a Python interface to the Sybase relational
database system. It supports all of the Python Database API, version
2.0 with extensions.
The module is...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |