Cygnite - A Modern Toolkit For Web Developers

The Elegant Way of Building Full-Featured Web Applications

Cygnite Dynamic Routing

Raw Queries


Database Raw Queries

Database Driver Supports By Cygnite

Cygnite Framework query builder currently supports the well known MySql database by default. Since we are using PDO as database abstraction layer, you can also write PDO queries to use against other databases.

Write raw queries

Cygnite Framework gives you flexibility to write raw queries alongside the Cyrus ORM, query builder, finders etc. Setup your database configuration in src/Apps/Configs/database.php file. You can mention your database name and primary key in model to let Cyrus ORM to know against which database you would like to run queries. Let us see basic example, how to fetch data, or insert/update using raw queries.

 // Return multiple users from table
 public function getUsers()
     return $this->query("SELECT * FROM `guest_book`")->fetchAll(\PDO::FETCH_ASSOC); 

 // return single row
 public function getUser($id)
     return $this->query("SELECT * FROM ".$this->tableName." where id =$id")->fetch();

 // insert or update query
 public function save()
     return $this->query("Your INSERT query")->execute();

You can also use dynamic finder method on model class to run raw queries as below.

 use Apps\Models\User;

  $user = User::sql("select * from users");  

Call Function Using Model Instance

 use Apps\Models\User;

 $user = new User();

o need to worry Cygnite will autoload all your models in runtime, so just create an object and concentrate on doing your application stuffs. Similarly you can execute your insert, update, delete queries using query() function.

You can also take an advantage of all PDO methods by using $this->pdo inside your model function and run queries.

Follow Us On Facebook Twitter Google+ Linkedin
Released Under The MIT Public License. Copyrights @2012-2017. Powered by- Sanjoy Dey Productions.