PHP致命错误:未被捕获的com_exception:源: ADODB.Connection
描述:参数类型错误,超出可接受范围或彼此冲突。在C:\ inetpub \ wwwroot \ SonReceipt \ api \ create_test.php:66
堆栈跟踪:
这是来自php文件create_test.php的错误消息:
按照消息显示,我认为问题所在是INSERT查询,但由于INSERT语句似乎还行,所以没有任何线索。
我在该论坛和其他网站上查看了类似的“ Uncaught com_exception”帖子,但它们并非完全属于此类。有人遇到过类似的事情吗?
TIA。
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// 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");
// database connection
$conn = new COM("ADODB.Connection");
$conn->Open("Provider=VFPOLEDB.1;Data Source=C:\inetpub\wwwroot\sonreceipt\RECEIPT.DBC;Password='';Collating Sequence=MACHINE");
// get posted data
$jsonData = '{"refnum":"1111-2222-3333", "paydate":"01/06/2018", "custname":"O. A. BECKLEY VENTURES", "custemail":"beckleyventures@gmail.com", "demandno":"DEMAND NOTE 001", "demanddate":"01/06/2018", "amount":15550.00, "recpdesc":"SONCAP", "paybank":"ZENITH BANK PLC", "payref":"0123456789"}';
$data = json_decode($jsonData);
// set payment values received
$jrefnum = $data->refnum;
$jpaydate = $data->paydate;
$jcustname = $data->custname;
$jcustemail = $data->custemail;
$jdemandno = $data->demandno;
$jdemanddate = $data->demanddate;
$jamount = $data->amount;
$jrecpdesc = $data->recpdesc;
$jpaybank = $data->paybank;
$jpayref = $data->payref;
// create the payment
if (create()){
echo "Payment was created.";
}
// if unable to create the payment, tell the user
else {
echo "Unable to create payment.";
}
// create payment
function create(){
global $conn, $jrefnum, $jpaydate, $jcustname, $jcustemail, $jdemandno, $jdemanddate, $jamount, $jrecpdesc, $jpaybank, $jpayref;
// sanitize
$srefnum=$jrefnum;
$spaydate=$jpaydate;
$scustname=$jcustname;
$scustemail=$jcustemail;
$sdemandno=$jdemandno;
$sdemanddate=$jdemanddate;
$samount=$jamount;
$srecpdesc=$jrecpdesc;
$spaybank=$jpaybank;
$spayref=$jpayref;
// query to insert record
$query = "INSERT INTO SON2100 (refnum, paydate, custname, custemail, demandno, demanddate, amount, recpdesc, paybank, payref)
VALUES ($srefnum, $spaydate, $scustname, $scustemail, $sdemandno, $sdemanddate, $samount, $srecpdesc, $spaybank, $spayref)";
// prepare query
$stmt = $conn->prepare($query);
// execute query
if($stmt->execute()){
//$stmt->close();
return true;
}
return false;
}
?>
答案 0 :(得分:0)
该错误实际上是由以下原因引起的:
未在字符字段的INSERT语句的VALUES子句中将php变量括在引号中。
与数字字段相反的情况。
请注意,提供给INSERT语句的值来自已解码的JSON字符串。请参见下面的工作代码。
decodeBool:forKey