Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL Stored Procedure from PHP

Chad L
Guest
 
Posts: n/a
#1: Nov 22 '05
I'm trying to execute a SQL stored procedure from PHP like so:

$sql = "exec ('usp_Locations_Sel 5065')";

if (! $result = mssql_query($sql,$DBid))
{
exit;

}

while( $row = mssql_fetch_array($result) ){
// blah blah

}

The Procedure works from SQL Query Analyzer, and returns a result set
of 4 rows. Other stored procedures, in which a single variable is
declared for return, also come back to PHP without any problem.
However, any procedure that returns a result set doesn't make it back
to PHP.

(I don't have mssql_bind(), etc)

Any help would be much appreciated.
CL


Steve
Guest
 
Posts: n/a
#2: Nov 22 '05

re: SQL Stored Procedure from PHP


[color=blue]
> I'm trying to execute a SQL stored procedure from PHP like so:[/color]
[color=blue]
> $sql = "exec ('usp_Locations_Sel 5065')";[/color]
[color=blue]
> However, any procedure that returns a result set doesn't make it back
> to PHP.[/color]

Not sure what you mean by "doesn't make it back". Do you get a PHP
error or is your $result empty or something else?

One possibility is that your stored proc is trying to return more than
one resultset - usually because it is returning the number of rows
affected as a second resultset. The PHP API doesn't handle this. To
stop it, in the stored proc add this line before the start of your
code:

SET NOCOUNT ON

---
Steve

Chad L
Guest
 
Posts: n/a
#3: Nov 22 '05

re: SQL Stored Procedure from PHP


Steve,

I get no errors, no messages, it simply doesn't do anything.

I don't believe the proc was returning anything more than just the
single result set but I'll give that a shot.

I appreciate your help
Chad

Steve
Guest
 
Posts: n/a
#4: Nov 22 '05

re: SQL Stored Procedure from PHP


[color=blue]
> I get no errors, no messages, it simply doesn't do anything.[/color]

Another possibility along the same lines is mentioned in the user note
by "brian_caughlin" in this man page:
<http://uk.php.net/manual/en/function.mssql-execute.php>.

---
Steve

Chad L
Guest
 
Posts: n/a
#5: Nov 22 '05

re: SQL Stored Procedure from PHP


SET NOCOUNT ON didn't help.

I am using PHP 4.3.4 with '--with-sybase=/usr/local/freetds' to access
the mssql functions and connect to SQL server.

I do not have the mssql functions mssql_next_result(),
mssql_execute(), mssql_bind().

Any suggestions would be greatly appreciated. I'm not getting very far
on this.

Thanks,
Chad

Closed Thread