Introduction
Installation
Getting started
Package Definition Reference
Connecting to Database
Common DB Operations
Filter
Handling Multiple Databases
How-Tos
Deployment
Credit
Feedback
Changelog

Zephyr API

Forum

<<-dbinfo class->>

before connecting to any database you must define a special class which provides some credentials to internal data access object of zephyr. you can create this class by extending zephyr's internal "abstractdbinfo" class. you must place this class in "helper" folder inside your package. lets have a look at the following dbinfo class. inside class constructor you set this credentials.

<?
class dbinfo extends abstractdbinfo 
{
	public function __construct()
	{
	        $this->dbhost = "localhost";
		$this->dbname = "student";
		$this->dbuser = "root";
		$this->dbpwd = "root";
		$this->dbtype = "mysql";
		$this->persist = 1;
	}
}
?>

most of these properties are self explanatory. as we used adoDB as data access layer for zephyr, so you can use almost every database type supported by adoDB without any hassle. however a little bit extra care is needed to use sqlite, please see the SQLite section for details.

zephyr comes with a minimal installation of adoDB with following drivers

- MySQL
- SQLite
- Postgresql
- MSSQL (Both ODBC and Normal)
- ODBC
- Oracle

however, you can update the default adoDB installation with your requirement. adoDB is placed in \thirdparty\adodb folder inside the root directory of zephyr.

there is a complete sample package which uses sqlite. you can find this package as "sqlite" inside packages folder.

<<-care for sqlite->>

as sqlite is a flat file database, so we need a little bit extra care to use sqlite. for best practise, create a separate folder under your package root for placing these sqlite databases. forexample, we create a folder named "sqlitedb' inside our package. our database name is "test.sqlite". lets see the sample dbinfo for this.

<?
class dbinfo extends abstractdbinfo
{
public function __construct()
{
$pm = new packagemanager();
$package_path = $pm->get_package_path(); //physical path to this package
$this->dbhost = $package_path."/sqlitedb/";
$this->dbname = "test.sqlite";
$this->dbtype = "sqlite";
$this->persist = 1;
}
}
?>

now you can access this sqlite database when you instantiate the data access object.

<<-using data access object (DAO) in actions->>

after creating your dbinfo class, you can perform database operations in your actions. zephyr provides an well managed data access object which you can instantiate anytime. here is a example which creates a table in your database, then insert some records, then fetch them and finally return to your view.

//viewreport.class.php

<?
class viewreport implements action { public $params; public function execute() { $dao = new DAO(); //instantiate Data Access Object $dao->execute("create table students (name varchar(100))"); $dao->execute('insert into students values("ayesha")'); $dao->execute('insert into students values("didar")'); $dao->execute('insert into students values("shahana")'); $dao->execute('insert into students values("tipoo")'); $result = $dao->selectBySQL("select * from students"); $data = array("students"=>$result); return array("view_file"=>"reports","data"=>$data); } }
?>

Well, this action instantiate the DAO which actually connects to the sqlite database as specified in dbinfo. then it creates a table named "students" and insert some data. finally, it fetch all records and pass them to "reports" template as a variable named "students" . lets look at our template reports.tpl which we must place inside "view" folder. this is a smarty template.

//reports.tpl
<h1>All Students</h1>
{foreach item=student from=$students name=std}
{$smarty.foreach.std.iteration}.{$student.name}<br>
{/foreach}

so what is the output? lets take a look below.

<<-supported database types->>

primarily we supply a limited version of adoDB with minimal drivers. so not every db will be supported by default. But if yo upgrade the default adoDB folder with your requirement, you will get complete support. Rightnow we are supporting only these drivers

- MySQL
- SQLite
- Postgresql
- MSSQL (Both ODBC and Normal)
- ODBC
- Oracle

however, you can update the default adoDB installation with your requirement. adoDB is placed in \thirdparty\adodb folder inside the root directory of zephyr.