Link to home
Start Free TrialLog in
Avatar of Overthere
Overthere

asked on

Php 5.5 and coding error with stored procedure

Hello folks,
  I am using PHP 5.5, IIS 8 Express and MS Sql Server. I have a stored procedure which I wish to call from my PHP coding.
I have posted the coding below. I have placed it in a function.
I keep receiving the error: "Parse error: syntax error, unexpected '*'" - on the line that executes the call.
(I have placed a exit in the coding further down so I can view the results of the return value.)
What am I doing wrong and what must I do to correct the problem??

  function mklog()
  
  {
      
     $compip = $_SERVER['REMOTE_ADDR'];
     $vmyid = $_SESSION['id'];
     $vbldid = $_SESSION['bldid'];
     $vname = $_SESSION['myname'];
     $servername=  $_SESSION["servername"];
     $uid = $_SESSION["uid"];      
     $pwd =  $_SESSION["pwd"];      
     $connectioninfo = array( "UID"=>$uid,
                          "PWD"=>$pwd,
                          "Database"=>$_SESSION['userdbname']);

     $curtime = date('h:i:s A');
     $curdate = date('m/d/Y');
     $vcreated = 'CREATED-' . $curtime;

     $tsql_callSP =
          *{ call ins_login(?,?,?,?,?,?,?,?) }*;
         


    $params = array(
                     array($bldid, SQL_SVR_PARAM_IN),
                     array($vmyid, SQL_SVR_PARAM_IN),
                     array($vname, SQL_SVR_PARAM_IN),
                     array($curdate, SQL_SVR_PARAM_IN),
                     array($curtime, SQL_SVR_PARAM_IN),
                     array($vcomip, SQL_SVR_PARAM_IN),
                     array($vcreated, SQL_SVR_PARAM_IN),
                     array($logid, SQL_SVR_PARAM_OUT)

                );


     $stmt = sqlsrv_prepare($conn,$connectioninfo,$tsql_callSP,$params); 
     if ($stmt == false)
       {
          die(print_r(sqlsrv_errors(), true));
       }

       // retreive the scope-identity which is the auto-generated pk 
       echo  $logid . "<br>";
       $_SESSION['LogId'] = $logid;
       echo  $_SESSION['LogId'];
     exit;
      // free resources
      sqlsrv_free_stmt( $stmt);
      sqlsrv_close( $conn);
  }  

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

In PHP this is an assignment statement.
$tsql_callSP =
          *{ call ins_login(?,?,?,?,?,?,?,?) }*;

Open in new window

But since the assigned value (right of the equal sign) is not a valid PHP statement, PHP fails with a parse error.  Only the first parse error will be displayed - after that the PHP parser stops.

Maybe the string bounded by asterisks should be enclosed in quotes?
Avatar of Overthere
Overthere

ASKER

Didn't work , same error....sigh
I am pretty sure the rest of my coding is good, it's just that one statement...another sigh
If there is another, such as inserting a revord, that's good too...I just need to have the scope identity returned...
Help me understand what you're trying to accomplish here.  What is the $tsql_callSP variable supposed to contain?
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Shame on me. The coding is a function that is incorporated within the page by the means of an include statement.
And you are right, what I pasted is missing the define for my $conn which is:

        $conn = sqlsrv_connect($servername,$connectioninfo);

Open in new window


 I don't know how that happened when I pasted it. I see that on the $tsql_callSP  statement, you enclosed it in single quotes, would you be as so kind as to explain why?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'd like to gently suggest that you step back from writing applications and take a little time to learn the PHP language.  There are so many assumptions in the language, that it is hard to just "pick it up" by following examples.  If you want some good learning resources consider using the resources suggested in this article.  Feel free to skip over anything in the "deep background" that you covered in college, but if there are any holes in your learning foundation, these resources can help fill in the gaps.  And the part about learning PHP comes from the best PHP authors and teachers in the world.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
I see you have no message option...
Thank you Ray for guidance once again and good articles... always appreciated...
The coding I posted works correctly and  very well.
Ray advice and assistance  was very helpful and appreciated.