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)