我有一个PHP类,它是管道/读取发送到特定电子邮件ID的电子邮件,并将其插入数据库表。这段代码非常好用。但现在我想提取以“1011”开头的邮件正文中的Number列表,并使用它来查询数据库。正文($ this->正文)可以有一个或10个以1011开头的数字。现在我想使用“1011”从数据库中获取必要的SELECT信息,并将其插入到另一个表中。但是这不起作用。如果我删除SELECT查询,我可以直接将“1011”插入到我的表中。但我想先插入“1011”之前选择此参数。 PLS帮助我!!!
$matches = array();
$pieces = explode(PHP_EOL, $this->body);
$matches = preg_grep("/1011/", $pieces);
//$results = implode(" | ",array_values($matches));
//echo "Terminal IDs: ".$results." ";
foreach ($matches as $columns)
{
$select = $this->pdo->query("SELECT * FROM tbl_atm_data1 WHERE terminal_id = '$columns' ");
$select = $select->fetchAll();
if(count($select) > 0) {
foreach($select AS $row) {
$this->sol_id =$row['sol_id'];
$this->timers =$row['timers'];
$this->atm_name=$row['atm_name'];
$this->terminal_id =$row['terminal_id'];
$insertFile = $this->pdo->prepare("INSERT INTO tbl_request_dump1(terminal_id,sol_id,timers,atm_name) VALUES (:terminal_id,:sol_id,:timers,:atm_name)");
$insertFile ->bindParam(':terminal_id', $columns);
$insertFile ->bindParam(':sol_id', $this->sol_id);
$insertFile ->bindParam(':timers', $this->timers);
$insertFile ->bindParam(':atm_name', $this->atm_name);
$insertFile->execute();
}
}else {
echo "No Terminal ID to Need to Save";
die();
}
}
答案 0 :(得分:0)
我注意到我的数据库表terminal_id是Integer数据类型,所以我转换了 $ column to Integer 它工作得很好!
$term=(int)$columns;
$select = $this->pdo->query("SELECT * FROM tbl_atm_data1 WHERE terminal_id = '$term'");
谢谢!