AQL (Astconf Query Language) is a SQL-like statement, which can be used to write and read asterisk config files library for PHP in an easy way. 中文版
AQL focuses on making control of asterisk config files easily, fast and reliably. Users can write and read asterisk config files by writing normal SQL-like statements, and no longer need to consider how to write the right settings.
Suggestion:
<?
include("aql.php");
// to query extension 8001 settings from sip.conf
$aql = new aql;
$aql->set('basedir','/etc/asterisk/');
$db = $aql->query("select * from sip.conf where section='8001'");
print_r($db);
?>
output:
Array
(
[8888] => Array
(
[type] => friend
.....
)
)
get source files from SVN: >svn export http://darwin.freeiris.org/svn/freeiris/addition/aql/
Coping inc/ to your script including folder.
Add one line at header of your script within aql.php, example:
<?
require("../inc/aql.php");
$a = new aql();
if (!$a->set('basedir','./')) {
echo __LINE__.' '.$a->get_error();
}
$a->query(....);
.....
?>
commandline interface looks like mysql monitor.
in aql source folder: chmod +x aqlcli.php ./aqlcli.php <config_base_path> example: ./aqlcli.php /etc/asterisk/ Welcome to the AQL command line interface. Commands end pass Enter key Your AQL Library version : 1.0 , AQL_Confparser Version : 0.3 type 'help' for help. AQLcli>select * from sip.conf (<-type this) you will see output data
set An options to AQL object.
Query AQL statements to config file and get results.
References with query language in detail please see Query Language Interface Reference
Commit all query command to AQL conf parser engine. System will call this function automatically, unless tune false to the option 'autucommit'.
# system step by step to run two query commands.
$AQL->set('autocommit','false');
$AQL->query("select * from sip.conf");
$AQL->query("delete from sip.conf where section='8001'");
$AQL->commit("sip.conf");
Means clean all commit command. Users will not use this function until tune false to the option 'autocommit'
Return string including the last error messages from config parser engine.
Get the number of affected rows by the last AQL commands.
The AQL Query syntax can be summarized as follows:
query from config files:
SELECT * FROM <config_file>
[WHERE <condition> [AND <condition> ...]]
[LIMIT [<offset>,]<count>]
edit keys :
UPDATE <config_file> SET key=value[,key2=value2]
[WHERE <condition> [AND <condition> ...]]
[LIMIT [<offset>,]<count>]
add new key :
ALTER TABLE <config_file> ADD key=value[,key2=value2...] [AFTER(keyname)|BEFORE(keyname)]
[WHERE <condition> [AND <condition> ...]]
[LIMIT [<offset>,]<count>]
delete key :
ALTER TABLE <config_file> DROP key,[key2...]
[WHERE <condition> [AND <condition> ...]]
[LIMIT [<offset>,]<count>]
add new section and datas:
INSERT INTO <config_file> SET key=value[,key2=value2]
delete section :
DELETE FROM <config_file>
[WHERE <condition> [AND <condition> ...]]
[LIMIT [<offset>,]<count>]
use other path(like $aql->set('basedir',path)) :
USE <path>
As with SQL, AQL keywords are case insensitive. but table-name and field and value are case sensitive.
Only key name “section =” can be supported, because “section” is unique in asterisk config files.
The optional WHERE clause filters the result set to those entities that meet one or more conditions. Each condition compares a property of the entity with a value using a comparison operator and multiple conditions are given with the AND keyword. AQL does not have an ”“OR”” operator.
# query results from 8001 to 8004 extensions. where section >= 8001 and section <= 8004 # query results from unsection in any files. where section = ''
comparison digit : = != < > <= >= match string : like '%string' like 'string%' like '%string%'
Note: like '%string%' is very slowly.
An optional LIMIT clause causes the query to stop returning results after the first count entities. The LIMIT can also include an offset to skip that many results to find the first result to return. An optional OFFSET clause can specify an offset if no LIMIT clause is present.
limit 10 limit 10,10
Function based interface inheriting aql_confparser.php. that advanced class, for the beginnger we suggest try to Query Language Interface.
return the version of aql_confparser.php
return the full data from database variable.
Note: database variable include all of config files.
return parsed conf from database.
return commit assigned list.
open config file from filename
Note: database variable include all of config files.
try to reload and reparse config with filename.
do commited change and save to config file.
checking database's filename exists, return true or false.
set database variable null.
assign append data around with section name.
$position:
assign delkey from section in config files.
add section with special name and data chunk.
drop section with section name.
Sun bing hoowa.sun@gmail.com.
Copyright © 2010, Fonoirs CO.,LTD.
You may distribute under the terms of either the GNU General Public License VERSION 2.
|
||||
| Freeiris爱好者QQ群 43185599 |