forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
2 years ago
|
#!/usr/bin/php -q
|
||
|
<?php
|
||
|
$dbPort = "5432";
|
||
|
$dbHost = "192.168.115.12";
|
||
|
$dbName = "portabilidade";
|
||
|
$dbUser = "contacte";
|
||
|
$dbPassword = "ctepgSQL";
|
||
|
$str = "host='$dbHost' port='$dbPort' dbname='$dbName' user='$dbUser' password='$dbPassword'";
|
||
|
$dbcon = pg_connect($str);
|
||
|
|
||
|
//verifica se a conexao foi criada com sucesso.
|
||
|
$statusCon = pg_connection_status($dbcon);
|
||
|
|
||
|
if ($statusCon === 0) {
|
||
|
$query = "insert into prefixo_importa( prefixo, prestadora, ini, fim) values( '%s', '%s', '%s', '%s')";
|
||
|
|
||
|
//$filePath = "C:\\wamp\\www\\simplesip\\scriptdb\\anatel\\movel\\prefixox_movel-22-11-2014.txt";
|
||
|
$filePath = "/var/lib/asterisk/scripts/anatel/movel/prefixox_movel-22-11-2014.txt";
|
||
|
$file = fopen($filePath, "r");
|
||
|
|
||
|
$result = pg_query($dbcon, "begin");
|
||
|
while (!feof($file)) {
|
||
|
$buffer = trim(fgets($file));
|
||
|
|
||
|
/*
|
||
|
* Layout arquivo
|
||
|
* 01 Prefixo char 07
|
||
|
02 Prestadora char 30
|
||
|
03 Num. da Faixa Inicial char 04
|
||
|
04 Num. da Faixa Final char 04
|
||
|
|
||
|
*/
|
||
|
if ($buffer) {
|
||
|
$prefixo = substr($buffer, 0, 7);
|
||
|
$prest = substr($buffer, 7, 30);
|
||
|
$ini = substr($buffer, 37, 4);
|
||
|
$fim = substr($buffer, 41, 4);
|
||
|
|
||
|
$queryExec = sprintf($query, $prefixo, $prest, $ini, $fim);
|
||
|
$result = pg_query($dbcon, $queryExec);
|
||
|
if (!$result) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($result) {
|
||
|
pg_query($dbcon, "commit");
|
||
|
echo "Arquivo importado com sucesso!\n";
|
||
|
} else {
|
||
|
$erro = error_get_last();
|
||
|
echo "Erro ao importar Arquivo!: Erro: " . $erro["message"] . "\n";
|
||
|
}
|
||
|
}
|
||
|
?>
|