<<-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. - MySQL 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. <? 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 <? 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> 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 however, you can update the default adoDB installation with your requirement. adoDB is placed in \thirdparty\adodb folder inside the root directory of zephyr.
|