Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 15 ■ INTRODUCTION TO THE ZEND FRAMEWORK^221

Defining Models


The next step is to create data models that will provide some meaningful data to the applica-
tion. The Zend Framework contains many useful classes that you can use for interacting with
databases. You will create your data models using these base classes, but first you need a database.

Setting Up a Database
Which database you use is entirely up to you. The examples in this chapter use the PostgreSQL
database, as it installs from package management on Debian Linux distributions. For your
specific system, the location of binaries may not be in the path, and the location of pg_hba.conf
may be different than shown.
First, you need to create a PostgreSQL user, to act as owner of the database, and section off
your application’s access from any other databases already running on your host. This is an
interactive command and should be run as the postgres user. Be sure to use a custom pass-
word for your database.

> createuser –P

Enter name of role to add: demouser
Enter password for new role: demopass
Enter it again: demopass
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE

Then create a database that is owned by the demouser user, is UTF-8 encoded, and is called
demodb.

> createdb -O demouser -E utf-8 demodb

CREATE DATABASE

Next, in order to enable access to your new database, the PostgreSQL host-based authen-
tication configuration (pg_hba.conf) must be edited so that your new user is given permission
to connect to the database. The following line grants local (Unix socket) access on demodb to
demouser using MD5 hashed passwords:

> pico -w /etc/postgresql/8.1/main/pg_hba.conf

local demodb demouser md5

Now reload the postgresql daemon, using either an init script or the pg_ctl binary.

> /etc/init.d/postgresql reload

McArthur_819-9C15.fm Page 221 Thursday, February 28, 2008 7:44 AM

Free download pdf