juddadredd Posted January 2, 2015 Share Posted January 2, 2015 (edited) Hi all, This is just an experiment to make sure that I can get data from a Stored Proc 'IF' and when I need to, so it's basically a THOUGHT EXERCISE. MSSQL 2014 I'm a noobie and need a hand, I've managed to get my Instance connected to the internet and I can query it using PHP and SQL, I can also look at views with no problem. I have it working as an "ADODB.Connection" and like I said it connects and I can query data and display results. Now I have coded a Stored Proc "GetMonthDays" in Sql Server: Which returns days 1 through xxx in a given month and also returns the Day name eg... Sat for each date 2014-01-01 Thurs 2014-01-02 Fri etc... It works perfectly and very fast so All cool with that side BUT... I want to be able to query the Database through a Stored Proc, I've spent all day trying to find a way to get this to work and I've hit a wall Can anyone please tell me IF it's A. possible and B. maybe if they are really really nice and share with me a code example that I can change to fit my needs ? This T-SQL returns what it needs to Begin EXEC dbo.qselGetMonthDays '2015-01-01' End Cheers JD Edited January 2, 2015 by juddadredd Quote Link to comment https://forums.phpfreaks.com/topic/293608-executing-a-sql-server-stored-procedure-in-php/ Share on other sites More sharing options...
CroNiX Posted January 2, 2015 Share Posted January 2, 2015 I believe it's just "CALL qselGetMonthDays('2015-01-01');" Quote Link to comment https://forums.phpfreaks.com/topic/293608-executing-a-sql-server-stored-procedure-in-php/#findComment-1501563 Share on other sites More sharing options...
Solution juddadredd Posted January 3, 2015 Author Solution Share Posted January 3, 2015 Hi ya Cronix, No it's actually this just incase it will help out anyone else - it now takes input from the webpage - calls the Stored Procedure and then dumps it out with a record count I've also coded some other routines now that will populate Tables from a Webpage Via a Stored Procedure - Hopefully make things less hackable. Cheers All <?PHP // Set up strings here for DB and Server connections $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn’t connect to SQL Server on $myServer");$selected = mssql_select_db($myDB, $dbhandle) or die("Couldn’t open database $myDB");echo $_GET['timestr'];$StartDate = $_GET['timestr']; //$StartDate = '2015-01-01'; test string$result = mssql_query("EXEC dbo.qselGetMonthDays @StartDate = '$StartDate'", $dbhandle);$numRows = mssql_num_rows($result);echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; while( $row = mssql_fetch_object( $result ) ){echo $row->DateField . " " . $row->DayField; echo '</br>';} mssql_close($dbhandle);?> Quote Link to comment https://forums.phpfreaks.com/topic/293608-executing-a-sql-server-stored-procedure-in-php/#findComment-1501607 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.