Thứ Năm, 24 tháng 4, 2014

MySQL [Getting Started with Zend Framework 2.0]

MySQL doesn't need an introduction—it is the world's most widely used open source database application. It's free and is available on the Internet to individuals and businesses that wish tdevelop their websites and applications usingthe MySQL database.

Zend Framework 2.0 has driver support for MySQL along with SQLite, PostgreSQL, and Microsoft SQL Server.

Our nexexercise will be to install MySQL on our development machine. MySQL is available for download from all Linux repositories. Windows and Mac users will havto download the installer from the MySQL website (http://dev.mysql.com/downloads/).

MySQL Server and Client need to be installed using the following steps; we will be using MySQL as our primary database in this book:

1.       In a standard Ubuntu installation, MySQL can be installed bexecuting the following command in the shell prompt:
$ sudo apt-get install mysql-server mysql-client

2.       After the installation is complete, MySQL Server will start automatically. To check if MySQL Server is running, run the following command:
$ sudo netstat -tap | grep mysql

3.       The command should give an output that is similar to the following; this means that the MySQL daemon is running:
tcp     0      0 localhost:mysql     *:*     LISTEN      923/mysqld

4.       Iffor some reason, MySQL Server is not runningyou can start the server by running
the restart command:
$ sudo service mysql restart


What just happened?
We have just installed MySQL; we have the LAMP stack ready too. Our nexstep will be to create a database in MySQL Server.
phpMyAdmin
phpMyAdmin is a free, open source web-based database administration tool written in PHP. phpMyAdmin provides a web-based UI to manage MySQL Database Server; add / remove / manage databases, users, privileges; and so on. In this book, we will be using phpMyAdmin as the database Administration Interface for managing our database(s).

Now thawe have Apache, PHP, and MySQL installed, our nexstep will be to create a blank database in MySQL Server.

For doing this, we need to install and configure phpMyAdmin in the Zend Server.

In our nextask we will be creating a MySQL database, creating users in the MySQL server and also grant them access permissions tconnect to the database and perform database operations.
To create a new database, open an instance of phpMyAdmin in your web browser and follow the steps described here:
1. Open phpMyAdmin in your web browser by visiting http://localhost/ phpmyadmin:


2. Choose Databases, enter the name of the new database as zf_app in Create nedatabase, and click on Create:



3. After creating the database, create a database user for this database; this can be done by selecting Add a new user from Privileges. Provide the following details:


After doing this you will get the following screen:

4. After the user is created, go to the Privileges section and choose Edit Privileges for the zf_user.
5. In the Database-specific privileges section, select the zf_app database.
6. You will be redirected to the privileges section of the zf_app database for the zf_user user. Choose Check All and click on Go.


You can notest the database by logging out of phpMyAdmin and logging in again with the user credentials of zf_userYou should now be able to see only the zf_app database.


What just happened?
We just created our first database in MySQL. We have also created a user in the database and mapped the user to the database with administrative rights; wcan now use these credentials in the application thawe will be building in our next chapters.

Now that you have the PHP web server up and running and also have a MySQL database, create a simple table called Students and add a few records to the table using phpMyAdmin.

Your task will be to create a simple PHP web page that will display all the records in the
Students table in the page.

Q1. What is the minimum version of PHP needed to run Zend Framework 2.0?

1.       PHP 4.3 and above
2.       PHP 5.2.0 and above
3.       PHP 5.3.3 and above
4.       PHP 5.4.7 and above

Q2. What is the default location of php.ini in the neZend Server installation?

1.       /home/<user>/etc/php/php.inc
2.       /etc/php/php.ini
3.       /var/www/php.ini
4.       /usr/local/zend/etc/php.ini


Summary


In this chapter we have learned the setup and configuration of Zend Server's PHP application stack. Wwent on to install MySQL Server and created our first database. In your exercises, you have learned about the installation of Git and phpMyAdmin.

In the next chapterwe will learn about the structure of a Zend Framework project and core MVcomponents such as views and controllers.

Không có nhận xét nào:

Đăng nhận xét