Read /dev/ttyUSB2 device from 3g dongle for incomming Caller ID number and send them to php script (Don’t forget to activate CLIP service from AT commands AT+CLIP=1) Main script that must be run in background

#!/bin/bash
 # Read ttyUSB2 device from 3g dongle for CLIP messages
# and send them to php script
 while :
do
	read -d,,,,0 RESPONSE < /dev/ttyUSB2;
	php pager.php $RESPONSE
	#echo $RESPONSE | grep +CLIP
	#sleep 1
done

The pager.php contains the following code:

<?php
include_once 'config.php';
if (isset($argv[3])) {
	$phone = str_replace('"', '', $argv[3]);
    if (is_numeric($phone)) {
        $stmt = $mysql->prepare("REPLACE INTO pager VALUES (:phone, NOW());");
        $stmt->bindParam(':phone', $phone);
        $stmt->execute();
    }
}
$mysql = null;
?>

And the config.php file:

<?php
 ### MYSQL MAIN CONFIG ###
define("MYSQL_USER", "mysql_user");
define("MYSQL_PASS", "mysql_pass");
define("MYSQL_URL",  "localhost");
define("MYSQL_DB",   "mysql_db");
$mysql = new PDO('mysql:host='.MYSQL_URL.';dbname='.MYSQL_DB, MYSQL_USER, MYSQL_PASS);
$mysql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
### DEFAULT TIMEZONE ###
date_default_timezone_set('Europe/Chisinau');
### ENABLE DEBUGING MODE ###
error_reporting(E_ALL);
ini_set('display_errors','On');
### UPLOAD BIG FILES ###
ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');
 ?>