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

OverthereAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
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?
0
OverthereAuthor Commented:
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
0
OverthereAuthor Commented:
If there is another, such as inserting a revord, that's good too...I just need to have the scope identity returned...
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Ray PaseurCommented:
Help me understand what you're trying to accomplish here.  What is the $tsql_callSP variable supposed to contain?
0
Ray PaseurCommented:
This will at least parse correctly, but the code does not make any sense.  The $conn variable appears to be a dependency, but it's undefined in the function.  Where is that variable coming from?
<?php // demo/temp_overthere.php
/**
* http://www.experts-exchange.com/questions/28864420/Php-5-5-and-coding-error-with-stored-procedure.html
*/
error_reporting(E_ALL);
echo '<pre>';


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
    ( [ $bldid,    SQL_SVR_PARAM_IN ]
    , [ $vmyid,    SQL_SVR_PARAM_IN ]
    , [ $vname,    SQL_SVR_PARAM_IN ]
    , [ $curdate,  SQL_SVR_PARAM_IN ]
    , [ $curtime,  SQL_SVR_PARAM_IN ]
    , [ $vcomip,   SQL_SVR_PARAM_IN ]
    , [ $vcreated, SQL_SVR_PARAM_IN ]
    , [ $logid,    SQL_SVR_PARAM_OUT ]
    )
    ;

    $stmt = sqlsrv_prepare($conn, $connectioninfo, $tsql_callSP, $params);
    if ($stmt == false)
    {
        trigger_error(sqlsrv_errors(), E_USER_ERROR);
    }

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

Open in new window

0
OverthereAuthor Commented:
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?
0
OverthereAuthor Commented:
Okay, I finally have it figured out. I found out that using the code structure, although correct according to MS examples, throws weird  errors and unpredictable results.
 
 
$tsql_callSP =
          *{ call ins_login(?,?,?,?,?,?,?,?) }*;

Open in new window


I took awhile but, I finally was able to do it.  The example you posted Ray, help me to think more from a sql angle than PHP, which sounds silly, but it jogged my brain.
I posted my solution below...inserts just fine and returns my pk as scope identity as defined in the SQL sproc..
{
      
     $xcomip = $_SERVER['REMOTE_ADDR'];
     $xagentid = $_SESSION['agentid'];
     $xbldid = $_SESSION['bidid'];
     $xfirstname = $_SESSION['firstname'];
     $curtime = date('m/d/Y h:i:s A');
     $curdate = date('m/d/Y h:i:s A');
     $xcreated = 'CREATED-' . $curtime;
     $servername=  $_SESSION["servername"];
     $uid = $_SESSION["uid"];      
     $pwd =  $_SESSION["pwd"];      
     $connectioninfo = array( "UID"=>$uid,
                          "PWD"=>$pwd,
                          "Database"=>$_SESSION['userdbname']);

 
     $conn = sqlsrv_connect($servername,$connectioninfo);
     if ($conn == FALSE)
       {
           die( print_r(sqlsrv_errors(),TRUE));
       }

   $myparams['RecId'] = intval(-2);
   $myparams['BldId'] = $xbidid;
   $myparams['AgentId'] = $xagentid;
   $myparams['FirstName'] = $xfirstname;
   $myparams['LoginDate'] = $curdate;
   $myparams['LoginTime'] = $curtime;
   $myparams['IP'] =  $xcompip;
   $myparams['RecStatus'] = $xcreated;

   $procedure_params = array(
             array(&$myparams['RecId'], SQLSRV_PARAM_OUT),
             array(&$myparams['BldId'], SQLSRV_PARAM_IN),
             array(&$myparams['AgentId'], SQLSRV_PARAM_IN),
             array(&$myparams['FirstName'], SQLSRV_PARAM_IN),
             array(&$myparams['LoginDate'], SQLSRV_PARAM_IN),
             array(&$myparams['LoginTime'], SQLSRV_PARAM_IN),
             array(&$myparams['IP'], SQLSRV_PARAM_IN),
             array(&$myparams['RecStatus'], SQLSRV_PARAM_IN)
             );

   $sql = "EXEC ins_login @RecId= ?,@BidId = ?, @AgentId = ?, @FirstName = ?, @LoginDate = ?, @LoginTime = ?, @IP = ?, @RecStatus = ?";

  $stmt = sqlsrv_prepare($conn,$sql, $procedure_params); 
  if ($stmt == false)
       {
          //die(print_r(sqlsrv_errors(), true));
          trigger_error(sqlsrv_errors(), E_USER_ERROR);
       }
  
  if (sqlsrv_execute($stmt))
    {
        while ($res = sqlsrv_next_result($stmt))
         {
             
         }
        
           print_r($myparams);
           // retreive the scope-identity it is the auto-generated pk 
           echo $myparams[@RecId];
           $_SESSION['AgentLog'] = $myparams[@RecId];

    }

   
      // free resources
      sqlsrv_free_stmt($sql);
      sqlsrv_free_stmt($stmt);
      sqlsrv_close( $conn);
  }  

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
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.
http://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
0
OverthereAuthor Commented:
I see you have no message option...
0
OverthereAuthor Commented:
Thank you Ray for guidance once again and good articles... always appreciated...
0
OverthereAuthor Commented:
The coding I posted works correctly and  very well.
Ray advice and assistance  was very helpful and appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.