SQLSTATE hy093无效的参数编号未绑定任何参数

时间:2019-04-04 11:17:07

标签: php pdo

我在php中收到一个错误,我很好奇,因为在我用来测试我的代码的5台设备中,只有1(一个)存在此问题。我不知道是什么原因造成的,以及如何防止这种情况再次发生。有办法解决这个问题吗?

  

sqlstate hy093无效的参数编号未绑定任何参数

我尝试查询的3(3)来检查它是否正常工作,并且所有这些查询都正常工作。我可以选择更新并将数据插入到我的数据库中。

<?php
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);

$Database = $json_obj->Database;
$Host = $json_obj->Host;
$ContactID = $json_obj->ContactID;
$FileAs = $json_obj->FileAs;
$FirstName = $json_obj->FirstName;
$MiddleName = $json_obj->MiddleName;
$LastName = $json_obj->LastName;
$Position = $json_obj->Position;
$Company = $json_obj->Company;
$CompanyID = $json_obj->CompanyID;
$RetailerType = $json_obj->RetailerType;
$PresStreet = $json_obj->PresStreet;
$PresBarangay = $json_obj->PresBarangay;
$PresDistrict = $json_obj->PresDistrict;
$PresTown = $json_obj->PresTown;
$PresProvince = $json_obj->PresProvince;
$PresCountry = $json_obj->PresCountry;
$Landmark = $json_obj->Landmark;
$Remarks = $json_obj->Remarks;
$RecordDate = $json_obj->RecordDate;
$StartTimeData = $json_obj->StartTime;
$EndTimeData = $json_obj->EndTime;
$Telephone1 = $json_obj->Telephone1;
$Telephone2 = $json_obj->Telephone2;
$Mobile = $json_obj->Mobile;
$MobilePhoto1 = $json_obj->MobilePhoto1;
$MobilePhoto2 = $json_obj->MobilePhoto2;
$MobilePhoto3 = $json_obj->MobilePhoto3;
$MobileVideo = $json_obj->MobileVideo;
$Email = $json_obj->Email;
$Employee = $json_obj->Employee;
$Customer = $json_obj->Customer;
$Supervisor = $json_obj->Supervisor;
$RecordLog = $json_obj->RecordLog;
$Deleted = $json_obj->Deleted;
$LastUpdated = $json_obj->LastUpdated;
$StartTime = date("h:i:s", strtotime($StartTimeData));
$EndTime = date("h:i:s", strtotime($EndTimeData));

$client_update = date("Y-m-d h:i:s", strtotime($LastUpdated));
$RDate = date("Y-m-d", strtotime($RecordDate));

$dbuser = "sa";
$dbpass = "micromax";

$conn;

try {
    $conn = new PDO("mysql:host=$Host;dbname=$Database;charset=utf8", $dbuser, $dbpass);
    $cursor = array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
}
catch(PDOException $e)
{   
    try {
        $conn = new PDO("sqlsrv:Server=$Host;Database=$Database", $dbuser, $dbpass);
        $conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8);
        $cursor = array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
    }
    catch(PDOException $e){
        $ar[] = array(
            'Message' => "Not Connected"
        );

        print json_encode($ar);
    }
}

$sql = $conn->prepare("SELECT ServerUpdate FROM tblContacts WHERE ContactID = '$ContactID' AND Deleted != '1'", $cursor);
$sql->execute();
$count = $sql->rowCount();

if($count > 0){
    $sql = $conn->prepare("UPDATE tblContacts SET 
            FileAs='$FileAs', 
            FirstName='$FirstName', 
            MiddleName='$MiddleName', 
            LastName='$LastName', 
            Position='$Position', 
            Company='$Company', 
            CompanyID='$CompanyID', 
            RetailerType='$RetailerType', 
            PresStreet='$PresStreet', 
            PresBarangay='$PresBarangay', 
            PresDistrict='$PresDistrict', 
            PresTown='$PresTown', 
            PresProvince='$PresProvince', 
            PresCountry='$PresCountry', 
            Landmark='$Landmark', 
            CustomerRemarks='$Remarks', 
            RecordDate='$RDate', 
            StartTime='$StartTime', 
            EndTime='$EndTime', 
            Telephone1='$Telephone1', 
            Telephone2='$Telephone2', 
            Mobile='$Mobile', 
            Email='$Email', 
            MobilePhoto1='$MobilePhoto1', 
            MobilePhoto2='$MobilePhoto2', 
            MobilePhoto3='$MobilePhoto3', 
            MobileVideo='$MobileVideo', 
            Employee='$Employee', 
            Customer='$Customer', 
            Supervisor='$Supervisor', 
            RecordLog = '$RecordLog', 
            Deleted = '$Deleted', 
            ClientUpdate = '$client_update' WHERE ContactID = '$ContactID'", $cursor);

            if($sql->execute()){
                $ar[] = array(
                    "Message" => "Inserted"
                );
            }
            else{
                $ar[] = array(
                    "Message" => "Error"
                );
            }
}
else{
    $sql = $conn->prepare("INSERT INTO tblContacts (ContactID, FileAs, FirstName, MiddleName, LastName, RetailerType, PresStreet, PresBarangay, PresDistrict, PresTown, PresProvince, PresCountry, Landmark, CustomerRemarks, RecordDate, StartTime, EndTime, Telephone1, Telephone2, Mobile, MobilePhoto1, MobilePhoto2, MobilePhoto3, MobileVideo, Email, Employee, Customer, Supervisor, RecordLog, Deleted, ClientUpdate, ServerUpdate) VALUES('$ContactID', '$FileAs', '$FirstName', '$MiddleName', '$LastName', '$RetailerType','$PresStreet', '$PresBarangay', '$PresDistrict', '$PresTown', '$PresProvince', '$PresCountry', '$Landmark', '$Remarks', '$RDate', '$StartTime', '$EndTime', '$Telephone1', '$Telephone2', '$Mobile', '$MobilePhoto1', '$MobilePhoto2', '$MobilePhoto3', '$MobileVideo', '$Email', '$Employee', '$Customer', '$Supervisor', '$RecordLog', '$Deleted', '$client_update', 0-01-0001)", $cursor);

    if($sql->execute()){
        $ar[] = array(
            "Message" => "Inserted"
        );
     }
}

print json_encode($ar);

$sql = null;
$conn = null;
?>

我使用的是PDO,代码与我的4位测试人员都可以正常工作,另一位出现错误是什么原因?

0 个答案:

没有答案