5

I am currently connecting sucessfully to an SQL database sat on a Windows 2008 using the following query;

$result = mssql_query("EXEC dbo.stored_procedure_name @param_level = 2");

I am basing my queries on existing code written in VB / ADO which looks like;

If level = "" Then level = 1

cmdTT.ActiveConnection = connStrTest1

set objParam=cmdTT.CreateParameter("@param_level", adInteger, adParamInput, 4, level)
cmdTT.Parameters.Append objParam

set rsTT = cmdTT.Execute

So what I attempted was the following;

$f = 2;

$stmt = mssql_init('dbo.stored_procedure_name', $mssql_link);

mssql_bind($stmt, "@param_level", $f, SQLINT4, false);

mssql_execute($stmt);

But no matter what the variation it always seems to print the print the screen the warning, "Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in ...".

Whats the best way for me to debug the issue here? Can anyone see a clear fix to my problem?

I'm currently connecting remotely to the database from a LAMP stack.

Many Thanks Ian

Zhorov
  • 28,486
  • 6
  • 27
  • 52
ismithuk
  • 51
  • 1
  • 3

3 Answers3

4

Is this from a linux server using FreeTDS? If so, I wonder if this is related to TDS Version. Try tds version = 8.0 in you /etc/freetds.conf

scotru
  • 2,563
  • 20
  • 37
1

I know it's an old post but am sure it will help someone.

You have to add mssql_free_statement($stmt) after executing.

  • This worked for me when I called `mssql_free_statement()` to close the current statement before creating a new one. This behavior varied for me. On one server the code ran fine *without* the `mssql_free_statement()` call. On another failing to call `mssql_free_statement()` caused every subsequent stored procedure call to fail. – leepowers Aug 14 '15 at 10:30
1

Run the contents of the stored procedure from w/in a sql editor with the parameters hard coded in. You'll get more verbose error messages that way.

Parris Varney
  • 11,320
  • 12
  • 47
  • 76
  • 1
    The query runs fine using the top method, but when I imitate with the mssql_execute function it falls over. I think its falling over on the mssql_bind stuff but don't know why. – ismithuk Aug 05 '11 at 15:13