MSSQL Stored Procedure

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Glavin
Forum Newbie
Posts: 1
Joined: Tue Jul 13, 2010 1:56 pm

MSSQL Stored Procedure

Post by Glavin »

Having some difficulty with stored procedures. I'm getting a boolean TRUE result back when executing the procedure, indicating it didn't fail, but I'm unable to retrieve any results. If I just perform a query on the procedure, i.e. "exec usp_ProcedureName @param1='value1', @param2='value2'", it does return the expected data.

Here's a snippet from my current code:

Code: Select all

        $sth = mssql_init($query, $this->dbh);        
        if(is_array($params))
        {            
            foreach($params as $name => $value)
            {
                $success = mssql_bind($sth, $name, $value, SQLVARCHAR, false, false);
                if(!$success)
                {
                    throw new \Errors\SqlException('Failed to bind paramater.', 0, print_r(array($query, $params, mssql_get_last_message()), true));
                }
            }
        }                                
        $result = mssql_execute($sth) or die('Failed to execute.');
        while($row = mssql_fetch_assoc($result))
        {
            //  Do stuff
        }
I get a warning saying: mssql_fetch_assoc() expects parameter 1 to be resource, boolean given. Can anyone tell me what I'm doing wrong? Or is this something with the stored procedure? I thought it was unlikely that the stored procedure would be the issue since just executing the procedure with mssql_query does work.

Thanks very much for any help, I appreciate it.
Post Reply