0% found this document useful (0 votes)
6 views2 pages

SQLite Entrevistadores

Php para acesso a Sqlite Data Base

Uploaded by

tresearchw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

SQLite Entrevistadores

Php para acesso a Sqlite Data Base

Uploaded by

tresearchw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php
$databasename = "Research.db";
$query = file_get_contents("php://input");
$sq = 'sqlite:' . $databasename;
$conn = opendatabase($sq);
$query = file_get_contents("php://input");
// if(file_exists( "data.txt" )){
// unlink("data.txt");
// }
$sth = $conn->prepare("Delete from Pesquisadores;");
try
{
$sth->execute();
}
catch(PDOException $e)
{
// echo "Statement failed: " . $e->getMessage();
// fwrite($fp, "Erro: ".$e->getMessage()."\n");
return false;
}
//$query = 'Delete from Pesquisadores; '.$query;

$conn = opendatabase($sq);

$fp = fopen('data.txt', 'w');


// fwrite($fp, $query."\n");

$V = substr_count($query, ";");
$QI = preg_split('/;/', $query, -1, PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE);

//$sth = $conn->prepare($query);
for ($i = 0; $i < $V; $i++) {
try
{
$conn->beginTransaction();
//$sth->execute();
$conn->query($QI[$i]);
// fwrite($fp, "Inserindo..."."\n");
$conn->commit();
}
catch(PDOException $e)
{
echo "Statement failed: " . $e->getMessage();
// fwrite($fp, "Erro: ".$e->getMessage()."\n");
return false;
}
}
//$sth->setFetchMode(PDO::FETCH_NUM);

$sth = $conn->prepare("Select PEQCOD, PEQNOME from Pesquisadores;");


try
{
//$conn->beginTransaction();
$sth->execute();
$sth->setFetchMode(PDO::FETCH_NUM);
// $conn->commit();
}
catch(PDOException $e)
{
// echo "Statement failed: " . $e->getMessage();
// fwrite($fp, "Erro: ".$e->getMessage()."\n");
return false;
}

$i = 0;
$array2 = array();
//while ($rows = $sth->fetch()) {
// $array2["$i"] = $rows;
// $i++;
//}

print json_encode($array2);

fclose($fp);

function opendatabase($sq){
try{
//return new SQLITE3("Research.db");
return new PDO($sq,"","",array(PDO::ATTR_PERSISTENT => true));
}catch(PDOException $e){
logerror($e->getMessage(), "opendatabase");
$fp = fopen('erro.txt', 'w');
// print "Error in open ".$e->getMessage();
// fwrite($fp, $e->getMessage()."\n");
fclose($fp);
}
}
?>

You might also like