Back to Top

How you can write Custom Queries in Modx

execute custom query in modx

From last few days, I am working on MODx Revolution. MODx is open source content management framework.Modx is basically based on chunks, snippets and resources.

so as I am working on a project, I need to do some customization for those parts which are not by default provided by MODx Revolution.

For some functionality, I want to make some custom queries.so today I am going to explain how you can write custom queries on Modx revolution.

Modx Revolution uses an XPDO for handling database queries and all.

Here,please have a look into the following queries:

$sql ="insert into modx_users (sEmail,sPassword) values('$email','$password')";
$stmt = $modx->prepare($sql);
$stmt- >execute();

Here, $modx is used, when working with MODx tables or to store any record into the table of the MODx database.

To fetch records from the database

$stmt = $modx->query("select username from modx_users where username = $username");
if ($stmt) {
	$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
}
else
{
	throw new Exception("SQL Failed: " . $sResultSQL);
}

That’s it.If you need clarification of the code or it doesn’t work in a particular situation, please let me know. As always, please post your thoughts below.

Also Read:

Conditional Chunk in Modx
Accordion Menu with Modx
Move Modx Revolution to Live Server

I hope this post will help you. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (2)

  1. […] few days, I have explained To send mail in modx and Execute Custom Query IN MODx and Today I am going to explain how to import users by external CSV file in MODx […]

  2. […] few days, I have explained To send mail in modx and Execute Custom Query IN MODx and Today I am going to explain how to import users by external CSV file in MODx […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Namespace in PHP

Posted on 7 years ago

Bhumi

How To hide WordPress Toolbar

Posted on 2 years ago

Bhumi

What is Predefined Interface in PHP

Posted on 3 years ago

Bhumi

How to convert RGB to Hex color PHP?

Posted on 5 years ago

Bhumi

How to Create a Zip File In PHP

Posted on 7 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 3 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 5 years ago

Bhumi