Skip to content

Instantly share code, notes, and snippets.

@AlexMocioi
Created June 10, 2013 14:50
Show Gist options
  • Save AlexMocioi/5749324 to your computer and use it in GitHub Desktop.
Save AlexMocioi/5749324 to your computer and use it in GitHub Desktop.
Exemplu de conexiune la postgresql si couchdb
<?php
// Connecting, selecting database
$dbconn = pg_connect("host= port= dbname= user= password=")
or die('Could not connect: ' . pg_last_error());
//Tre sa fac validarea asta doar pentru TC.1
$crotalie = 'RO03000021724';
// Performing SQL query
$query = 'select apt.cod_crotalie
from apia_bd2010.application_tag apt
join apia_bd2010.administrativ_tag_plata atp on apt.id=atp.app_tag_id
where atp.cod_diagnostic=\'OK\' and apt.cod_crotalie=\''.$crotalie.
'\' union
select apt.cod_crotalie
from apia_bd2011.application_tag apt
join apia_bd2011.administrativ_tag_plata atp on apt.id=atp.app_tag_id
where atp.cod_diagnostic=\'OK\' and apt.cod_crotalie=\''.$crotalie.'\'';
echo $query;
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$eLaViorel = false;
while ($cod = pg_fetch_result($result, 'cod_crotalie')) {
$eLaViorel = true;
return;
}
if ($eLaViorel){
//scrie-l in lista
} else {
//Il caut si in 2012 sa vad daca l-a cerut VL
$body = get_from_url("http://host:5984/bd2012/_design/corectii_verificari/_view/toate_TC2VL?key=[\"VL\",\"".$crotalie."\"]")
$couchResponse = json_decode($body['content'],true);
//Daca e ceva aici, inseamna ca l-a cerut si atunci il scriu in fisier -> are rows.length > 0
}
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
//Acum trebuie sa verific TC.2 daca le-am platit ca TC.2 si in 2012
$body = get_from_url("http://172.16.0.52:5984/bd2012/_design/corectii_verificari/_view/toate_TC2VL?key=[\"TC.2\",\"".$crotalie."\"]")
$couchResponse = json_decode($body['content'],true);
//Daca e ceva aici, inseamna ca l-a cerut si atunci il scriu in fisier
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment