PHP AGI 脚本没有插入数据库
PHP AGI script doesn't insert into database
有 AGI 脚本:
#!/usr/bin/php
<?php
require_once "phpagi.php";
$agi = new AGI();
$oper_name = $argv[1];
$did_number = $argv[2];
$conn = new mysqli("localhost", "root", "passss", "mydatabase");
$sql = "insert into did_checking values (NOW(), '$did_number', 1, '$oper_name')";
if ($conn->query($sql) === TRUE) {
echo $date . ": " . "DID " . $did_number . " is alive through " . $oper_name . "\n";
} else {
echo $date, " Error: " . $sql . " " . $conn->error;
}
$conn->close();
$agi->set_variable("DIDNUM", $did_number);
$agi->set_variable("OPERNAME", $oper_name);
unset ($agi);
?>
和一段 Asterisk 拨号方案:
[from-gsm]
exten => 8906,1,NoOp(${CALLERID(num)})
exten => 8906,n,Set(OPER_NAME='OPER1')
exten => 8906,n,Agi(did_checking.php,${OPERNAME},${CALLERID(num)})
exten => 8906,n,NoOp(DIDNUM: ${DIDNUM})
exten => 8906,n,NoOp(OPERNAME: ${OPERNAME})
结果数据库中没有新记录,尽管这些行:
$agi->set_variable("DIDNUM", $did_number);
$agi->set_variable("OPERNAME", $oper_name);
已执行,因为我可以在 Asterisk 控制台中看到结果。
但是当我在 Linux 控制台中执行脚本时,插入了一条新记录。
您可能需要明确 COMMIT
交易。在某些情况下,当处理一个包时,将启动一个事务,该事务需要在条目永久存在之前提交。
有 AGI 脚本:
#!/usr/bin/php
<?php
require_once "phpagi.php";
$agi = new AGI();
$oper_name = $argv[1];
$did_number = $argv[2];
$conn = new mysqli("localhost", "root", "passss", "mydatabase");
$sql = "insert into did_checking values (NOW(), '$did_number', 1, '$oper_name')";
if ($conn->query($sql) === TRUE) {
echo $date . ": " . "DID " . $did_number . " is alive through " . $oper_name . "\n";
} else {
echo $date, " Error: " . $sql . " " . $conn->error;
}
$conn->close();
$agi->set_variable("DIDNUM", $did_number);
$agi->set_variable("OPERNAME", $oper_name);
unset ($agi);
?>
和一段 Asterisk 拨号方案:
[from-gsm]
exten => 8906,1,NoOp(${CALLERID(num)})
exten => 8906,n,Set(OPER_NAME='OPER1')
exten => 8906,n,Agi(did_checking.php,${OPERNAME},${CALLERID(num)})
exten => 8906,n,NoOp(DIDNUM: ${DIDNUM})
exten => 8906,n,NoOp(OPERNAME: ${OPERNAME})
结果数据库中没有新记录,尽管这些行:
$agi->set_variable("DIDNUM", $did_number);
$agi->set_variable("OPERNAME", $oper_name);
已执行,因为我可以在 Asterisk 控制台中看到结果。
但是当我在 Linux 控制台中执行脚本时,插入了一条新记录。
您可能需要明确 COMMIT
交易。在某些情况下,当处理一个包时,将启动一个事务,该事务需要在条目永久存在之前提交。