Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP致命错误:未捕获com_异常-插入VFP9数据库_Php_Foxpro - Fatal编程技术网

PHP致命错误:未捕获com_异常-插入VFP9数据库

PHP致命错误:未捕获com_异常-插入VFP9数据库,php,foxpro,Php,Foxpro,PHP致命错误:未捕获com_异常:源:ADODB.Connection说明:参数类型错误、超出可接受范围或相互冲突。在C:\inetpub\wwwroot\sonreceive\api\create\u test.php:66中 堆栈跟踪: C:\inetpub\wwwroot\sonreceive\api\create\u test.php(66):com->prepare('INSERT-INTO-SON…')) C:\inetpub\wwwroot\sonreceive\api\crea

PHP致命错误:未捕获com_异常:源:ADODB.Connection
说明:参数类型错误、超出可接受范围或相互冲突。在C:\inetpub\wwwroot\sonreceive\api\create\u test.php:66中 堆栈跟踪:

  • C:\inetpub\wwwroot\sonreceive\api\create\u test.php(66):com->prepare('INSERT-INTO-SON…'))
  • C:\inetpub\wwwroot\sonreceive\api\create\u test.php(35):create()
  • {main} 在第66行的C:\inetpub\wwwroot\sonreceive\api\create\u test.php中抛出
  • 这是php文件create_test.php中的错误消息:

    根据这条消息,我认为问题在于INSERT查询,但没有任何线索,因为INSERT语句似乎没有问题

    我在这个论坛和其他网站上看过类似的“未捕获的com_例外”帖子,但它们并不完全属于这种类型。有人遇到过类似的情况吗

    蒂亚


    错误实际上是由以下原因引起的:

  • 在字符字段的INSERT语句的VALUES子句中,不将php变量括在引号中

  • 数字字段的情况正好相反

  • 请注意,提供给INSERT语句的值来自解码的JSON字符串。请参阅下面的工作代码

    ?php 
    
    // required headers
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Methods: POST");
    header("Access-Control-Max-Age: 3600");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
    
    // get database connection
    $conn = new COM("ADODB.Connection");
    $conn->Open("Provider=VFPOLEDB.1;Data Source=C:\inetpub\wwwroot\sonservices\RECEIPT.DBC;Password='';Collating Sequence=MACHINE");
    
    class Payment{
    
        // object properties
        public $refnum;
        public $paydate;
        public $custname;
        public $custemail;
        public $demandno;
        public $demanddate;
        public $amount;
        public $recpdesc;
        public $paybank;
        public $payref;
    
        // create payment
        function create(){
    
            global $conn;
    
            // convert to string values
            $this->refnum=strval($this->refnum);
            $this->paydate=strval($this->paydate);
            $this->custname=strval($this->custname);
            $this->custemail=strval($this->custemail);
            $this->demandno=strval($this->demandno);
            $this->demanddate=strval($this->demanddate);
            $this->amount=strval($this->amount);
            $this->recpdesc=strval($this->recpdesc);
            $this->paybank=strval($this->paybank);
            $this->payref=strval($this->payref);
    
            // query to insert record
            $query = "INSERT INTO SON2100  
                VALUES ('', '$this->refnum', '$this->paydate', '', '', '$this->custname', '$this->custemail', '$this->demandno', '$this->demanddate', $this->amount, '$this->recpdesc', '$this->paybank', '$this->payref', '')";
    
            // execute query
            if($conn->execute($query)){
                return true;
            } 
            return false;
        }   
    }
    
    // prepare payment object
    $pymt = New Payment();
    
    // get posted data
    $data = json_decode(file_get_contents("php://input"));
    
    // set payment property values and sanitize
    $pymt->refnum = htmlspecialchars(strip_tags($data->refnum));
    $pymt->paydate = htmlspecialchars(strip_tags($data->paydate));
    $pymt->custname = htmlspecialchars(strip_tags($data->custname));
    $pymt->custemail = htmlspecialchars(strip_tags($data->custemail));
    $pymt->demandno = htmlspecialchars(strip_tags($data->demandno));
    $pymt->demanddate = htmlspecialchars(strip_tags($data->demanddate));
    $pymt->amount = htmlspecialchars(strip_tags($data->amount));
    $pymt->recpdesc = htmlspecialchars(strip_tags($data->recpdesc));
    $pymt->paybank = htmlspecialchars(strip_tags($data->paybank));
    $pymt->payref = htmlspecialchars(strip_tags($data->payref));
    
    // create the payment
    if ($pymt->create()){
        echo "Payment was created.";
    }
    
    // if unable to create the payment, tell the user
    else{
        echo "Unable to create payment.";
    }
    
    ?>
    

    您是否确认所提供的值实际上是其各自字段的正确类型。VFP对此非常严格。您是否尝试过减少语句并只传递部分字段以找出导致错误的原因?谢谢您的建议。是的,值的类型是正确的,但是在减少语句并用空字符串填充值时,我发现INSERT语句无法识别PHP变量($variablename)。因此出现了uncaught com_execption:syntax error。仍然需要找到一种方法让INSERT语句接受VALUES子句中的PHP变量。
    ?php 
    
    // required headers
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Methods: POST");
    header("Access-Control-Max-Age: 3600");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
    
    // get database connection
    $conn = new COM("ADODB.Connection");
    $conn->Open("Provider=VFPOLEDB.1;Data Source=C:\inetpub\wwwroot\sonservices\RECEIPT.DBC;Password='';Collating Sequence=MACHINE");
    
    class Payment{
    
        // object properties
        public $refnum;
        public $paydate;
        public $custname;
        public $custemail;
        public $demandno;
        public $demanddate;
        public $amount;
        public $recpdesc;
        public $paybank;
        public $payref;
    
        // create payment
        function create(){
    
            global $conn;
    
            // convert to string values
            $this->refnum=strval($this->refnum);
            $this->paydate=strval($this->paydate);
            $this->custname=strval($this->custname);
            $this->custemail=strval($this->custemail);
            $this->demandno=strval($this->demandno);
            $this->demanddate=strval($this->demanddate);
            $this->amount=strval($this->amount);
            $this->recpdesc=strval($this->recpdesc);
            $this->paybank=strval($this->paybank);
            $this->payref=strval($this->payref);
    
            // query to insert record
            $query = "INSERT INTO SON2100  
                VALUES ('', '$this->refnum', '$this->paydate', '', '', '$this->custname', '$this->custemail', '$this->demandno', '$this->demanddate', $this->amount, '$this->recpdesc', '$this->paybank', '$this->payref', '')";
    
            // execute query
            if($conn->execute($query)){
                return true;
            } 
            return false;
        }   
    }
    
    // prepare payment object
    $pymt = New Payment();
    
    // get posted data
    $data = json_decode(file_get_contents("php://input"));
    
    // set payment property values and sanitize
    $pymt->refnum = htmlspecialchars(strip_tags($data->refnum));
    $pymt->paydate = htmlspecialchars(strip_tags($data->paydate));
    $pymt->custname = htmlspecialchars(strip_tags($data->custname));
    $pymt->custemail = htmlspecialchars(strip_tags($data->custemail));
    $pymt->demandno = htmlspecialchars(strip_tags($data->demandno));
    $pymt->demanddate = htmlspecialchars(strip_tags($data->demanddate));
    $pymt->amount = htmlspecialchars(strip_tags($data->amount));
    $pymt->recpdesc = htmlspecialchars(strip_tags($data->recpdesc));
    $pymt->paybank = htmlspecialchars(strip_tags($data->paybank));
    $pymt->payref = htmlspecialchars(strip_tags($data->payref));
    
    // create the payment
    if ($pymt->create()){
        echo "Payment was created.";
    }
    
    // if unable to create the payment, tell the user
    else{
        echo "Unable to create payment.";
    }
    
    ?>