Jump to content

executing stored procedure in php


codrgii

Recommended Posts

i want to execute my SQL stored procedure to return its values in php when i execute it through my script. i can execute it fine through php but it dosen't return its results, i need it to return its select and count results so that i can see them in php, how do i go about this?

Link to comment
Share on other sites

something like this

 

*untested*

USE Users
GO
CREATE PROC sp_GetNumUsers
@UserGroup INT,
RETURN (SELECT COUNT(*) FROM Users WHERE Group = @UserGroup)

$link = mssql_connect($myServer, $myUser, $myPass);
$d = mssql_select_db($myDB, $link);
$query = mssql_init("sp_GetNumUsers", $link);
$UserGroup = 4;
$UserCount = 0;
mssql_bind($query, "@UserGroup", $UserGroup, SQLFLT8); 
mssql_bind($query, "RETVAL", &$UserCount, SQLINT2);
mssql_execute($query);
echo "$UserCount Users in Group $UserGroup";

Link to comment
Share on other sites

This is close to what my procedure is all about

 

if @modeis = 1
   BEGIN

while @i < 7011
   BEGIN
                 insert into table (account) VALUES (@ACC)
                 set @i = @i + 27

   END
   END
select * from table
select count (*) from table

 

Again i just want to see the select and count results from this sql server procedure onto my php script

Link to comment
Share on other sites

I actually put

 

my SQL stored procedure to return its values in php

which you missed out on your quote.  on php, not on sql server which you gave.

 

The select statement from the procedure, would be clearer for me on php showing the results, and would get the job done than adding a return, anyone know a few examples how to do this? as i've never really needed to show results from a procedure until now

Link to comment
Share on other sites

Is a SP returns something it returns to the requester.. if php is the requester then its going to return their!!!!!

 

There are two basic elements to return values:

[*]putting your SELECT query results in a variable and

[*]using the RETURN function to return your variable contents. Remember, use return values to have the stored procedure kick back a single value, not an entire record.

If you need more output from your stored procedure than just a single value, the OUTPUT function would be more appropriate.

 

as your returning a single value (the count) you sould use return..

 

its funny how you have no idea how to do this but want to do it your way!

in anycase, continue doing it the why you want!.. if that works for you!

Link to comment
Share on other sites

rather than returning the results in the procedure, i prefer using

 

select * from table
select count (*) from table

 

can't i still see the results through php? if so what examples can you give?

 

I asked if it was possible, if not then i'll learn another way, but first need a lil guidance and recommendation to what the best way to do it, also providing an example how to do it through PHP

 

thanks for your fast response.  :)

Link to comment
Share on other sites

alright.

 

PHP

$query = "EXEC FIND '790620270',1";
$result = odbc_exec($con, $query);
$res = odbc_result($result, 1); //this line needs changed, shows just 1 result

echo ''.$res.'';

 

the above, only shows just one result out from the select * from, and dosen't show the coun(*) result either, not sure how to make it show all the results...

Link to comment
Share on other sites

Tried that but getting

 

Column 'table.column' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

 

however its not that important, again looking for answers on how to show all the results in php using a sp

Link to comment
Share on other sites

Lol'ed.

 

Your the one not reading the topic, take a min to have a lil read over it again, all your doing here is providing me with _sql_ examples disregarding your first post which didn't help but was in php, i don't need to improve any part of the procedure, as it's fine and doing what im asking it to, all i need is advice and guidance on how to do it as i previously said in my earlier post - ignore the codes if you have to, i just needed a few examples how to show all the results through php using a sp.  If you don't know to or just messing around, just simply don't post

 

Also, when did i do any insisting saying i was right ?

Wrong topic? :)

Link to comment
Share on other sites

rather than returning the results in the procedure, i prefer using

 

select * from table
select count (*) from table

 

can't i still see the results through php? if so what examples can you give?

 

First quote here asking what was possible, and if this was possible, you asked for codes, i gave you them, you fail.

 

Techie Out!

 

Nice one.

 

 

Moving on, hopefully someone else will help me with this, providing just examples on how to show results in php using a sp, which is what i asked for at the very first post i made.

Link to comment
Share on other sites

How do i make the sp show all the results? select * from table result and the count (*) result? i've tried this but at best can only make it come back showing just 1 result from the select (last result selected)...

 

I'll try myself and read more about how sp works in php, pretty sure this would have to be an array of results...in the meantime will appreciate any guidance on this  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.