Executing a SQL Server Stored Procedure in PHP

  • 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

  • I'm confused.

    Were you able to call your GetMonthDays procedure but you want to use procedures to call data from SQL? If that's the case, it would be the same thing using the appropriate code inside the stored procedures.

    If you haven't been able to call your procedure from your PHP code, I can't help you but maybe someone else can or you'll have better luck in a PHP forum.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I'm writing a calendar just to build up my skill set and get a better understanding of T-SQL, you know find the first day of the month - find out what day name it is - display blanks until the 1st is reached if it doesnt fall on a monday - then draw a calendar - and populate each day with any info that matches to the date ETC.... Easy stuff and ALL working so far in MS Access - and not even broken a sweat doing it - BUT I want to push myself.

    I can use the MS Access front end to display a Calendar but its messy and UGLY and I want to be able to control the layout better so I created an HTML and CSS WEB BASED Calendar - which looks really nice - again not very hard to do.

    It currently shows Data from a predefined view BUT I would like it to be based on a Stored Proc with Params and NOT Data directly from a table.

    say I have the following:

    Sat 03/01/2015 Xmas shopping

    Sun 04/01/2015 Buy Chicken

    What I need is an example of running a SP through PHP on an EXTRENAL website to return the Data.

    EXTERNAL PHP Website Hosted by my Internet Provider

    Connects to my PC at HOME by - IP Port, Username, Password and Database (my ado string works)

    Opens my SQL Server DAtabase and Executes my SP with @Param (say 2015-01-04)

    Which Returns

    @Return Data to PHP (Sun 04/01/2015 Buy Chicken)

    Which I then Display nicely and then job 90% done

    I only want my website to be able to run either VIEWS or SP for interigating and populating the Database

    I hope that makes sense. 🙂

  • Hi Luis thanks for the help - I made a very simple rookie mistake I had only given myself limited access to the Database structure.

    A quick play with my security settings and everthings working fine now.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply