php mysql存储过程,解析错误:语法错误,意外T_STRING

时间:2013-09-19 00:23:41

标签: php mysql stored-procedures

我有这个代码

{ <?php
include 'koneksi.php';

$idAgent = $_GET["rqid"];
$ipAgent = $_SERVER['REMOTE_ADDR'];

$app = $_GET["app"];
$action = $_GET["action"];

$org = $_GET["org"];
$des = $_GET["des"];

$trainNo = $_GET["train_no"];
$depDate = $_GET["dep_date"];

$query = "SELECT cekRQID('$idAgent','$ipAgent') as jml;";
//echo($query);
$hasil = mysql_query($query);
$data  = mysql_fetch_array($hasil);
$channelOK = $data['jml'];  

if ($channelOK == "1") {
    if ($app == "information" && $action == "get_seat_map") {

        $query="SELECT 0 as err_code, '$org' as org, '$des' as des, '$trainNo' as train_no, $depDate as dep_date ";
        $hasil1 = mysql_query($query);

        $rows1 = array();
        while ($r1 = mysql_fetch_assoc($hasil1)){
            $rows1 = $r1;
        }

        $tglnya = date('Ymd',$depDate); //STR_TO_DATE('$depDate','%Y%m%d')

        $query = mysql_query("CALL GET_SEAT_MAP('$org','$des','$trainNo',STR_TO_DATE('$depDate','%Y%m%d'),@TEST);") or die mysql_error();
        $query = mysql_query("SELECT @TEST;") or die mysql_error();
        //echo($query);
        while($row = mysql_fetch_row($query))
        {           
            $query = $row[0];
        }

        $hasil = mysql_query($query);
        //echo($query);


        $rows = array();
        $index= 0;
        $bufk0 = "";
        $body = 0;

        while ($r = mysql_fetch_row($hasil)){
            $curfk0 = $r[0].$r[1];
            if( $bufk0 != $curfk0 ){
                $head[$curfk0] = array ( $r[0],$r[1]);  
                $out2[$curfk0][] =  array( $r[2],$r[3],$r[4],$r[5],$r[6],$r[7] );
            } else {                    
                $out2[$curfk0][] =  array( $r[2],$r[3],$r[4],$r[5],$r[6],$r[7] );                   
            }               
            $bufk0 = $r[0].$r[1];
            $bufindex = $index;
            $headindex = $head ;
            $index++;
        }

    }

if (is_array($values)){
    foreach ($head as $key => $val ){
        $final['seat_map'][] = array( $val[0],$val[1], $out2[$key] );       
    }   
}


header('Content-type: application/json');
echo json_encode($rows1+$final);
}

?>

}

当我运行此代码时,我收到一些错误消息: 解析错误:语法错误,第37行/var/www/html/sgetseatmap.php中的意外T_STRING

代码:

$query = mysql_query("CALL GET_SEAT_MAP('$org','$des','$trainNo',STR_TO_DATE('$depDate','%Y%m%d'),@TEST);") or die mysql_error();

我无法弄清楚为什么会发生这种情况,非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

您有以下两行:

or die mysql_error();

虽然你应该为检查错误而鼓掌(这在我们看到的问题中非常罕见),但这种语法是错误的。 die是一个函数,因此参数必须在括号中:

or die(mysql_error());

另一方面,您也应该停止使用mysql_xxx函数,因为它们已被弃用。您应该使用PDO或mysqli,并且最好使用带参数的预准备语句而不是插值字符串。