简体   繁体   中英

Cant call stored procedure from PHP

Can someone point out whats wrong with my php code for calling stored procedure in mssql. The following sql query works fine in mssql studio:

EXEC updateRecord 'Record','Closed','Jon','query test4','',''

Here is the php code that Im using to try and call the updateRecord:

<?php
 $Record = $_POST['record'];
 $Stat = $_POST['Status'];
 $Tech = $_POST['Tech'];
 $Action = $POST['Action'];
 $Date = date("Y/m/d");
 $time = date("G:i:s");
 //connect to sql
 $hostname = '127.0.0.1\SQLserver';
 $options = array('Database'=>'CallHistory', 'CharacterSet' => 'UTF-8');
 $conn = sqlsrv_connect($hostname, $options); 
 if(!is_resource($conn))
 { 
 echo 'Could not connect: ';
 var_dump(sqlsrv_errors(SQLSRV_ERR_ALL)); 
 exit(0);
 }

 //    echo "Success";
 //    sqlsrv_close($conn);

 // DB queries

 if (empty($_POST['record']) && empty($_POST['Statut'])&&empty($_POST['Tech']) && empty($_POST['Action']))
 {
 echo "CHoose at least one";
 }
else
{
$query1 = "exec updateRecord $Record,$Stat,$Tech,$Action,$Date,$time";
}
$ask = sqlsrv_query($conn, $query1);
sqlsrv_fetch($ask);
.........
?>

What am I forgetting....? The server seems to return an empty response and the actual record is not updated.

got it to work:

$query1 = "EXEC updateRecord @Record = '$Record', @Status = '$Stat', @Tech = '$Tech', @Date = '$Date', @time = '$time', @Actions = '$Action'";

thanks to this: https://stackoverflow.com/a/44911709

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM