ngecoding.com logo
Raw SQL Query in Phalcon Framework

Raw SQL Query in Phalcon Framework

//if(youLikeIt || itHelpsYou)clickShare();

Phalcon is a high perfomance PHP framework based on MVC pattern.  Phalcon has good performance in handle many request/second compared to other PHP framework, such as : Laravel, Zend, Code Igniter, and Kohana.

This tutorial will show you how to call raw SQL query for insert,update,select, and delete in Phalcon PHP Framework. 

1. Select

This example shows you how to call raw select from Phalcon controller class.

public function selectAction()
{
	$result=$this->db->query("SELECT employee_id,employee_name FROM employee order by employee_id desc");
						
	while($row=$result->fetchArray())
	{
		echo $row['employee_id']." ".$row['employee_name']."<br>";
	}
}

 

2. Insert

This example shows you how to call raw insert from Phalcon controller class.

public function insertAction()
{
	$success=$this->db->execute("INSERT INTO employee (employee_id,employee_name)
							VALUES ('14','Aditya Nugraha')");
						
	if($success)echo "Success!!";
	else echo "Failed!!";
}

 

3. Update

This example shows you how to call raw update from Phalcon controller class.

public function updateAction()
{
	$success=$this->db->execute("UPDATE employee SET employee_name='Aditya'
								WHERE employee_id='14'");
						
	if($success)
	{
		$updatedCount=$this->db->affectedRows(); 
		echo $updatedCount." rows updated";
	}
	else echo "Failed!!";
}

 

4. Delete

This example shows you how to call raw delete from Phalcon controller class.

public function deleteAction()
{
	$success=$this->db->execute("DELETE FROM employee
								WHERE employee_id='14'");
						
	if($success)
	{
		$updatedCount=$this->db->affectedRows(); 
		echo $updatedCount." rows deleted";
	}
	else echo "Failed!!";
}
//if(youLikeIt || itHelpsYou)clickShare();
//Advertisements
Take a Break //non-technical articles
Hot Topics //most used tags
Email Subscriptions //We won't spam you. Honest!

Enter your email address:

Delivered by FeedBurner