SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to execute sql stored procedures?

    Hi,

    Im using MS SQL and PHP, how do you execute a stored procedure?

    atm i am using :
    $proc = mssql_init("supCreateNewUser", $uname, $fname,$ulevel, '');
    $createuser = mssql_execute($proc);

    But i get the following errors:
    Warning: Wrong parameter count for mssql_init() on line 27

    Warning: mssql_execute(): supplied argument is not a valid MS SQL-Statement resource on line 28

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Massachusetts
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mssql_init can only accept two arguments (one of which is optional):

    http://us2.php.net/manual/en/function.mssql-init.php

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm ok well init dont work, so how would i run a stored procedure?

  4. #4
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cheeky Chino
    Hmm ok well init dont work, so how would i run a stored procedure?
    One click away from the link posted above, and I found the following.

    PHP Code:
    mssql_bind($my_procedure"@OutputParameter"SQLVARCHARtrue);
    $result mssql_execute($my_procedure);
    while(
    mssql_next_recordset($result)) {
    ## do something

    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry im a little lost i dont understand, what im using atm and am still getting "not a valid MS SQL statement resource" error is as follows:

    $varchar = "SQLVARCHAR";
    my_procedure = "supCreateNewUser";
    mssql_bind($my_procedure, "@loginid", $varchar, true);
    $result = mssql_execute($my_procedure);

    I dont understand also how i pass my values to my stored procedure...

    Like if i have
    "CREATE PROCEDURE supCreateNewUser (@loginid varchar(30), @fullname varchar(50),@userlevelid int, @usergroupid int) AS"

    How do i pass the loginid,fullname,userlevelid and usergroupid to the procedure?

    *confused*

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /******************************************
    /* This IS What Worked
    /******************************************

    $query = mssql_init("supCreateNewUser");
    mssql_bind($query,"@loginid",$uname,SQLVARCHAR);
    mssql_bind($query,"@fullname",$fname,SQLVARCHAR);
    mssql_bind($query,"@userlevelid",$ulevelid,SQLINT1);
    mssql_bind($query,"@usergroupid",$usergroupid,SQLINT2);
    mssql_bind($query,"@DisplayOutput",$displayoutput,SQLINT1);
    $createuser = mssql_execute($query);


    Thanks for the input guys


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •