I am trying to access a SQL Server stored procedure from PHP and am having difficulty with the syntax.
Firstly the connection to SQL Server is established no problem but I cannot access the SP.
I have tried following two described methods I found on the web but without success.
My SP has three fields ID, NAME and EMAIL and I want to pass the ID and get back the corresponding NAME and EMAIL.
The two methods I have tried are shown below. I really need to see a worked exaple if possible.
Also how do I tell PHP which SQL Server database it is accessing?
Any help appreciated.
CAB
<?php
// connect to database
include_once('connectMSSQL.php');
$ID=1;
$NAME="";
$email="";
$qry=mssql_init("myprocedure",$connectionstring);
mssql_bind($qry, "@id", $ID, FALSE);
mssql_bind($qry, "@name",$NAME, FALSE);
mssql_bind($qry, "@email", $EMAIL,FALSE );
$result=mssql_execute($qry) or die("QUERY FAILED");
echo "<P>STORED PROC WAS SUCCESSFULLY ACCESSED";
echo $ID;
echo $NAME;
echo $EMAIL;
echo "<P>TASK COMPLETE : ";
echo date("d/m/y @ H:i:s");
?>
results in ...
Fatal error: Call to undefined function mssql_init() in c:\Inetpub\ on line 19
And ...
<?php
// connect to database
include_once('connectMSSQL.php');
$ID=1;
$NAME="";
$email="";
$qry="EXEC myprocedure @id=$ID,$NAME,$EMAIL";
$result=odbc_exec($connectionstring,$qry) or die("QUERY FAILED TO EXECUTE");
echo "<P>TEST STORED PROC ACCESS - TASK STARTED : ";
echo date("d/m/y @ H:i:s");
echo "<P>STORED PROC WAS SUCCESSFULLY ACCESSED";
echo $ID;
echo $NAME;
echo $EMAIL;
echo "<P>TASK COMPLETE : ";
echo date("d/m/y @ H:i:s");
?>
results in ...
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','., SQL state 37000 in SQLExecDirect in c:\Inetpub\ on line 16
Firstly the connection to SQL Server is established no problem but I cannot access the SP.
I have tried following two described methods I found on the web but without success.
My SP has three fields ID, NAME and EMAIL and I want to pass the ID and get back the corresponding NAME and EMAIL.
The two methods I have tried are shown below. I really need to see a worked exaple if possible.
Also how do I tell PHP which SQL Server database it is accessing?
Any help appreciated.
CAB
<?php
// connect to database
include_once('connectMSSQL.php');
$ID=1;
$NAME="";
$email="";
$qry=mssql_init("myprocedure",$connectionstring);
mssql_bind($qry, "@id", $ID, FALSE);
mssql_bind($qry, "@name",$NAME, FALSE);
mssql_bind($qry, "@email", $EMAIL,FALSE );
$result=mssql_execute($qry) or die("QUERY FAILED");
echo "<P>STORED PROC WAS SUCCESSFULLY ACCESSED";
echo $ID;
echo $NAME;
echo $EMAIL;
echo "<P>TASK COMPLETE : ";
echo date("d/m/y @ H:i:s");
?>
results in ...
Fatal error: Call to undefined function mssql_init() in c:\Inetpub\ on line 19
And ...
<?php
// connect to database
include_once('connectMSSQL.php');
$ID=1;
$NAME="";
$email="";
$qry="EXEC myprocedure @id=$ID,$NAME,$EMAIL";
$result=odbc_exec($connectionstring,$qry) or die("QUERY FAILED TO EXECUTE");
echo "<P>TEST STORED PROC ACCESS - TASK STARTED : ";
echo date("d/m/y @ H:i:s");
echo "<P>STORED PROC WAS SUCCESSFULLY ACCESSED";
echo $ID;
echo $NAME;
echo $EMAIL;
echo "<P>TASK COMPLETE : ";
echo date("d/m/y @ H:i:s");
?>
results in ...
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','., SQL state 37000 in SQLExecDirect in c:\Inetpub\ on line 16