codrgii Posted June 2, 2009 Share Posted June 2, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/ Share on other sites More sharing options...
MadTechie Posted June 2, 2009 Share Posted June 2, 2009 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"; Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848173 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 didn't work i forgot to mention the procedure has 2 parameters, the first parameter is 9 numbers long and the last one is 1 number long, still need help on this one :X Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848255 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 What didn't work? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848320 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 The php code, is there any other way to show the results of the procedure baring in mind my 2 parameters? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848483 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 What code, mines an example, yours i havn't seen, without any useful data i'm not sure what i can say! Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848501 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848513 Share on other sites More sharing options...
trq Posted June 3, 2009 Share Posted June 3, 2009 Again, why not post some relevent code? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848514 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 Also your not returning any thing! try this SET @usr_count = (select count (*) from table) RETURN @usr_count Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848522 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848573 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 Make your minid up rather than returning the results in the procedure, i prefer using but you started with i want to execute my SQL stored procedure to return its values Hows that working for you ? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848633 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848646 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848649 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848657 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 Can you post some PHP code your using also the full SP, i'm not using MSSQL here, but i'll see if i an get something returning Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848682 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848700 Share on other sites More sharing options...
MadTechie Posted June 3, 2009 Share Posted June 3, 2009 okay firstly i don't get the reasoning behind having it as two statements ? select * from table select count (*) from table select count (*) as Count, * from table Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848791 Share on other sites More sharing options...
codrgii Posted June 3, 2009 Author Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-848862 Share on other sites More sharing options...
MadTechie Posted June 4, 2009 Share Posted June 4, 2009 however its not that important, again looking for answers on how to show all the results in php using a sp Gezzz, I try to help and you have no idea what your doing, yet insist your right read back 6 posts! I personally give up, with you. Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-849415 Share on other sites More sharing options...
codrgii Posted June 4, 2009 Author Share Posted June 4, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-849421 Share on other sites More sharing options...
MadTechie Posted June 4, 2009 Share Posted June 4, 2009 i don't need to improve any part of the procedure, as it's fine LMAO, sure.. I have given you 3 ways to return data, via last call, field returns and output.. these are the ONLY options.. Techie Out! Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-849436 Share on other sites More sharing options...
codrgii Posted June 4, 2009 Author Share Posted June 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-849452 Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 @codrgii, are you looking for help or a competition? Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-849457 Share on other sites More sharing options...
codrgii Posted June 4, 2009 Author Share Posted June 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160713-executing-stored-procedure-in-php/#findComment-849617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.