Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-16-2009, 06:28 PM   PM User | #1
Coyote6
Regular Coder

 
Join Date: May 2009
Location: Moore, OK
Posts: 277
Thanks: 10
Thanked 41 Times in 41 Posts
Coyote6 is an unknown quantity at this point
[ODBC SQL Server Driver]Cursor type changed, SQL state 01S02

I'm hoping someone has solved this issue before. I'm using an odbc_connection to an MsSQL database. It works on using stored procedures with select statements and it works on update statements as long as they do not involve any variables. But as soon as I use a variable it breaks the procedure giving me this error.

Code:
PHP Warning:  odbc_execute() [<a href='function.odbc-execute'>function.odbc-execute</a>]: SQL error: [Microsoft][ODBC SQL Server Driver]Cursor type changed, SQL state 01S02 in SQLExecute in XXXXXXXXXXX on line XX
MsSQL Code
Code:
CREATE TABLE [test] (
[id] INT NOT NULL IDENTITY PRIMARY KEY,
[name] VARCHAR(25)
)

INSERT INTO [test] 
([name])
VALUES
('Bob')

CREATE PROCEDURE [select_test]
@in_id INT
AS 
SELECT [name]
FROM [test]
WHERE [id]=@in_id

CREATE PROCEDURE [update_test_1]
AS
UPDATE [test]
SET [name]='Bill'
WHERE [id]=1

CREATE PROCEDURE [update_test_2]
@in_id INT
AS
UPDATE [test]
SET [name]='Ted'
WHERE [id]=@in_id
PHP Code:
include 'config.php';
$dbc odbc_connect(DBUSERPASSWORD);

### SELECT EXAMPLE ###
### WORKS ###

// Prep the params.
$params = array (1);
$query 'EXEC select_test @in_id=?';

// Query the db.
$ps odbc_prepare($dbc$query);
$r odbc_execute ($ps$params);

// Return the first field of the first record.
while ($row odbc_fetch_array ($ps)) {
    foreach (
$row as $ro) {
        echo 
$ro;
    }
}

### UPDATE 1 EXAMPLE ###
### WORKS ###

// Prep the params.
$params = array ();
$query 'EXEC update_test_1';

// Query the db.
$ps odbc_prepare($dbc$query);
$r odbc_execute ($ps$params);

// Return num rows affected.
echo odbc_num_rows($ps);

### UPDATE 2 EXAMPLE ###
### ERRORS OUT ###

// Prep the params.
$params = array (1);
$query 'EXEC update_test_2 @in_id=?';

// Query the db.
$ps odbc_prepare($dbc$query);
$r odbc_execute ($ps$params);

// Return num rows affected.
echo odbc_num_rows($ps);

### UPDATE 3 EXAMPLE ###
### WORKS ###

// Prep the params.
$params = array (1);
$query "UPDATE [test] SET [name]='Fred' WHERE [id]=?";

// Query the db.
$ps odbc_prepare($dbc$query);
$r odbc_execute ($ps$params);

// Return num rows affected.
echo odbc_num_rows($ps); 
Any ideas on how to get the update stored procedure with variables to work is greatly appreciated. Thanks.
Coyote6 is offline   Reply With Quote
Reply

Bookmarks

Tags
changed, cursor, error, odbc, type

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:37 PM.


Advertisement
Log in to turn off these ads.