Skip to content

Instantly share code, notes, and snippets.

@aldomendez
Created April 9, 2013 23:46
Show Gist options
  • Save aldomendez/5350468 to your computer and use it in GitHub Desktop.
Save aldomendez/5350468 to your computer and use it in GitHub Desktop.
Sirve de prueba para saber si se cuenta con sqlite instalado en PHP, ademas de que sirve como base para hacer aplicaciones sencillas
<?php
try
{
//open the database
$db = new PDO('sqlite:dogsDb_PDO.sqlite');
//delete the table if exists so I can start with a fresh table
$db->exec("drop table if exists Dogs");
//create the database
$db->exec("CREATE TABLE if not exists Dogs (Id INTEGER PRIMARY KEY, Breed TEXT, Name TEXT, Age INTEGER)");
//insert some data...
$db->exec("INSERT INTO Dogs (Breed, Name, Age) VALUES ('Labrador', 'Tank', 2);".
"INSERT INTO Dogs (Breed, Name, Age) VALUES ('Husky', 'Glacier', 7); " .
"INSERT INTO Dogs (Breed, Name, Age) VALUES ('Golden-Doodle', 'Ellie', 4);");
//now output the data to a simple html table...
print "<table border=1>";
print "<tr><td>Id</td><td>Breed</td><td>Name</td><td>Age</td></tr>";
$result = $db->query('SELECT * FROM Dogs');
foreach($result as $row)
{
print "<tr><td>".$row['Id']."</td>";
print "<td>".$row['Breed']."</td>";
print "<td>".$row['Name']."</td>";
print "<td>".$row['Age']."</td></tr>";
}
print "</table>";
// close the database connection
$db = NULL;
}
catch(PDOException $e)
{
print 'Exception : '.$e->getMessage();
}
/* foreach(PDO::getAvailableDrivers() as $driver)
{
echo $driver.'<br />';
}
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment