পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 8, 2017

Phalcon - Query Language

Phalcon Query Language (PHQL) also called as PhalconQL is a high-level SQL dialect which standardizes SQL queries for the database systems supported by Phalcon.
It includes a parser, written in C, which translates the syntax in target RDBMS.
Here is a list of some of the prominent features of Phalcon query language −

  • For security of web application, it uses bound parameters.
  • Tables are treated as models whereas columns are treated as class attributes.
  • All the data manipulation statements are used to prevent data loss which can occur.
  • SQL injection is prevented by keeping SQL query call one at a time.

Creating a PHQL Query

Queries are created by instantiating class Phalcon\Mvc\Model\Query.

Example

// Instantiate the Query 
$query = new Query( 
   "SELECT * FROM Users", 
   $this->getDI() 
);  

// Execute the query returning a result if any 
$cars = $query->execute(); 
In the previous chapters, we have seen the working of scaffold web application named blog tutorial. It included searching categories as per name or slug.
Following is the code included for searchAction.
public function searchAction() {  
   $numberPage = 1; 
   if ($this->request->isPost()) { 
      $query = Criteria::fromInput($this->di, "Categories", $_POST); 
      $this->session->conditions = $query->getConditions(); 
   } else { 
      $numberPage = $this->request->getQuery("page", "int"); 
      if ($numberPage <= 0) { 
         $numberPage = 1; 
      } 
   } 
   
   $parameters = array(); 
   if ($this->session->conditions) { 
      $parameters["conditions"] = $this->session->conditions; 
   } 
   
   // $parameters["order"] = "id"; 
   $categories = Categories::find($parameters); 
   if (count($categories) == 0) { 
      $this->flash->notice("The search did not find any categories"); 
      
      return $this->dispatcher->forward(array( 
         "controller" => "categories", 
         "action" => "index" 
      )); 
   } 
   
   $paginator = new \Phalcon\Paginator\Adapter\Model(array( 
      "data" => $categories, 
      "limit"=> 10, 
      "page" => $numberPage 
   )); 
   
   $page = $paginator->getPaginate(); 
   $this->view->setVar("page", $page); 
}
The PHQL query executed (highlighted) in the controller will fetch all the results as per the search condition. The result of any search query as per condition will be displayed as in the screenshot.
Following is the output received on successful execution of the above code.
PHQL

PHQL Life Cycle

Being a high-level language, PHQL provides the ability to the developers to personalize and customize various aspects as per requirements.
Following is the life cycle of each PHQL statement executed in Phalcon −
  • Every PHQL statement is parsed and converted as an Intermediate Representation (IR) which is completely independent of the SQL implemented by the database system.
  • The IR is converted to SQL statement as per the database system which is used in the web application. SQL statements generated are associated with the model.
  • All PHQL statements are parsed once and cached in the memory. If the same statement result is executed, it will help in faster performance.
Life Cycle

No comments:

Post a Comment