AGI sample – currency converter using web service

Bellow is an AGI sample to convert currency using a web service:

Step 1) create an extension in /etc/asterisk/extensions_custom.conf

[ext-local-custom]
exten => *777,1,AGI(currency.php)
exten => *777,n,hangup()

Step 2) Create currency.php in /var/lib/asterisk/agi-bin

#!/usr/bin/php -q
answer();

//fetch the web service and store the result into $curr
$fromCurrency="USD";
$toCurrency="MYR";
$res=file_get_contents("http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=$fromCurrency&ToCurrency=$toCurrency");
$xml = new SimpleXMLElement($res);
$curr=$xml[0];

$agi->text2wav("Currency rate from $fromCurrency to $toCurrency is");
$agi->say_number($curr);
$agi->text2wav("Thank you");
$agi->hangup();
?>
Continue Reading

How to backup/Restore in mysql

Dump all databases for backup. Backup file is sql commands to recreate all db’s.

# mysqldump -u root -ppassword --opt > alldatabases.sql

Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword
 --databases databasename >/tmp/databasename.sql

Dump a table from a database.

# mysqldump -c -u username -password databasename tablename > /tablename.sql

Restore database (or database table) from backup.

# mysql -u username -password databasename < /tmp/databasename.sql

Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO
TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY
 'n' (field1,field2,field3);
Continue Reading