我使用sqlsrv_query方法在PHP中得到空响应

时间:2019-11-27 10:10:35

标签: php api get

master $ kubectl get po
NAME                        READY   STATUS      RESTARTS   AGE
corn-job-1574850360-srwf6   0/1     Completed   0          44s

master $ kubectl logs -f corn-job-1574850360-srwf6
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
100   219  100   219    0     0     39      0  0:00:05  0:00:05 --:--:--    54

$ query =“将INSERT插入dbo.SPL(GcmRegId,PartyName,PersonName,MobileNo,EmailID,strCategory,CreatedAt)VALUES('$ GcmRegId','$ PartyName','$ PersonName','$ MobileNo',' $ EmailID','$ strCategory',getdate())“;     $ var = array($ GcmRegId,$ PartyName,$ PersonName,$ MobileNo,$ EmailID,$ strCategory,$ createdAt);
    $ result = sqlsrv_query($ pdo,$ query,$ var);
        如果($结果){             $ register = sqlsrv_fetch_array($ result,(SQLSRV_FETCH_ASSOC));             // $ response [“ register”] = $ register;             $ response [“ register”] [“ GcmRegId”] = $ register [“ GcmRegId”];             $ response [“ register”] [“ PartyName”] = $ register [“ PartyName”];             $ response [“ register”] [“ PersonName”] = $ register [“ PersonName”];             $ response [“ register”] [“ MobileNo”] = $ register [“ MobileNo”];             $ response [“ register”] [“ EmailID”] = $ register [“ EmailID”];             $ response [“ register”] [“ strCategory”] = $ register [“ strCategory”];             $ response [“ register”] [“ createdAt”] = $ register [“ createdAt”];             $ response [“ responce_code”] = 200;             $ response [“ error_code”] = 0;             $ response [“ error_msg”] =“注册成功”;             // echo json_encode($ register);             回声json_encode($ response);

2 个答案:

答案 0 :(得分:0)

[Input:]    
<?php
    #$conn = mysqli_connect("localhost", "root", "1234","spl_database");
    $response = array("error" => FALSE);
    error_reporting(E_ALL);

    include 'db_connect.php';
    $db = new db_connect();
    $pdo = $db->connect();

    // echo "hello";
    // echo json_encode($response);

    if (isset($_POST['GcmRegId']) && isset($_POST['PartyName']) && isset($_POST['PersonName']) && isset($_POST['MobileNo']) && isset($_POST['EmailID']) && isset($_POST['strCategory']) && isset($_POST['createdAt']))
    { 

        $GcmRegId = $_POST['GcmRegId'];
        $PartyName = $_POST['PartyName'];
        $PersonName = $_POST['PersonName'];
        $MobileNo = $_POST['MobileNo'];
        $EmailID = $_POST['EmailID'];
        $strCategory = $_POST['strCategory'];
        $createdAt = $_POST['createdAt'];

        $query = "SELECT * FROM dbo.SPL WHERE MobileNo = $MobileNo";
        $result = sqlsrv_query($pdo,$query);
        $result = sqlsrv_has_rows($result);
        if ($result === true) {
            $response["error_code"] = 0;
            $response["error_msg"] = " Alredy register with" . $MobileNo;
            echo json_encode($response);
        }else{
            $query = "INSERT INTO dbo.SPL (GcmRegId,PartyName,PersonName,MobileNo,EmailID,strCategory,createdAt) VALUES ('$GcmRegId','$PartyName','$PersonName','$MobileNo','$EmailID','$strCategory',getdate())";
            $var = array($GcmRegId,$PartyName,$PersonName,$MobileNo,$EmailID,$strCategory,$createdAt);   
            $result = sqlsrv_query($pdo,$query,$var);
            if ($result) {
                $register = sqlsrv_fetch_array($result,(SQLSRV_FETCH_ASSOC));
                $response["register"] = $register;
                $response["register"]["GcmRegId"] = $register . $GcmRegId;
                $response["register"]["PartyName"] = $register . $PartyName;
                $response["register"]["PersonName"] = $register. $PersonName;
                $response["register"]["MobileNo"] = $register . $MobileNo; 
                $response["register"]["EmailID"] = $register . $EmailID;
                $response["register"]["strCategory"] = $register . $strCategory;
                $response["register"]["createdAt"] = $register . $createdAt;
                $response["responce_code"] = 200;
                $response["error_code"] = 0;
                $response["error_msg"] = "Registration successfull";
                echo json_encode($response);
            }else{
                $response["error_code"] = 1;
                $response["error_msg"] = "Registration unsuccessfull";
                echo json_encode($response);
            }
        }enter code here
    }


    ?>

答案 1 :(得分:0)

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in springdata.SpringDataConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]