English 中文(简体)
Phalcon - Database Connectivity
  • 时间:2024-12-22

Phalcon - Database Connectivity


Previous Page Next Page  

In this chapter, we will discuss the database connectivity related to Phalcon.

Creation of Database and Design

We will focus on creating a database for blogs which maintains posts along with the categories as per the entries of users.

Database Name: blog-tutorial

Query used for creating the database −

drop database blog-tutorial (if exists) 
create database blog-tutorial 

After creation of the database, the database will be psted as shown in the following screenshot.

Database

Phalcon uses commands for creation of models, controllers, and even projects. Let’s see how it works.

Step 1 − Create a project named blog-tutorial.

Project Name

Step 2 − Configure the web apppcation that connects to the database which we created for managing blogs.

<?php  
return new PhalconConfig (array ( 
    database  => array ( 
       adapter   =>  Mysql , 
       host      =>  localhost , 
       username  =>  root , 
      //  dbname    =>  blog_tutorial , 
       password  =>   , 
       name      =>  blog_tutorial , 
   ), 
    apppcation  => array ( 
       controllersDir  => __DIR__ .  /../../app/controllers/ , 
       modelsDir       => __DIR__ .  /../../app/models/ , 
       viewsDir        => __DIR__ .  /../../app/views/ , 
       baseUri         =>  /blog-tutorial/ , 
   ) 
)); 
Advertisements