PHP open database

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of TestDatabases
*
* @author user
*/
function openDatabase() {
if($db = new PDO(“sqlite:/apacheWebsite/Calendar/database/database.data”)) {
$db->exec(‘CREATE TABLE calendar (id INTEGER PRIMARY KEY,
title TEXT, description TEXT, startDate TEXT,
startTime TEXT, endDate TEXT, endTime TEXT)’);
}
else print ‘could not create database’;
$db->null;

//   $result = $db->query(‘SELECT * FROM calendar’);
//   var_dump($result->fetchArray());
}

function insertIntoDatabase($record) {
if ($db = new PDO(“sqlite:/apacheWebsite/Calendar/database/database.data”)) {
$sql = “INSERT INTO calendar (title, description, startDate,
startTime, endDate, endTime) VALUES (:title,
:description,:startDate,:startTime,
:endDate,:endTime)”;
print ‘show data for title ‘.$_POST[‘title’];
$sth = $db->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(‘:title’=>$_POST[‘title’],’description’=>$_POST[‘description’],
‘:startDate’=>$_POST[‘startDate’], ‘:startTime’=>$record[0],
‘:endDate’=>$record[1], ‘:endTime’=>$record[2]))
or die(print_r($db->errorInfo(), true));
}
else print ‘problem loading data into database’;
}

function retrieveFromDatabase($startDate) {
$db = new SQLite3(“calendar.data”);
print(‘SELECT * FROM calendar WHERE startDate = “2005-05-12″‘);
$result = $db->query(‘SELECT * FROM calendar WHERE startDate= ‘.'”‘.$startDate.'”‘);
while ($row = $result->fetchArray()) {
var_dump($row);
}
//        return $result;

}

//retrieveFromDatabase(“2005-05-12”);

?>

Leave a Reply