有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);
?>
和一个星号拨号计划:
[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控制台中执行脚本时,会插入一条新记录。
答案 0 :(得分:1)
您可能需要明确COMMIT
交易。在某些情况下,当处理一个软件包时,将启动一个事务,该事务需要在条目永久存在之前进行提交。