$modx->db->select("*", " modx_jobs", "" , "date DESC" , "20")<?php
$stmt = $modx->query("SELECT * FROM modx_jobs ORDER BY date DESC LIMIT 20");
if ($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// do stuff with each row of the result
}
}
?>$modx->db->insert( $sendShout, "modx_shouts");
It will work for now, but again, the DBAPI is deprecated in Revo and will be removed in a future release. That said, the DBAPI can easily be made an Extra in the future if you want to plan to continue to use it for your Extras. But I highly recommend creating an xPDO model in the future for your MODx Extras that use database tables, as this will make it easier to port those to other databases when the MODx core is available for them, not to mention will provide a consistent API into your Extra’s data that can be utilized by generic MODx Snippets and Plugins in the same way core data is (see getValue for instance, which allows you to get a column value from any xPDO table class, not just core MODx tables).
I did read other posts about using custom tables etc and it did seem rather complex for what was once a simple task. I know why this is the road with REV, it was stated in the posts I read. That was a nice simple solution to display tables from the database, is there a simple solution to INSERT tables as well?
I am creating a json feed shoutbox and using ajax, users will add a table to the DB. I had this working in EVO using INSERT but thought I would now try REV. What would I need to do to achieve a simple $_POST to INSERT solution using the new modx methods?
I tried this and it did work...
$modx->db->insert( $sendShout, "modx_shouts");
is this the correct way to add values to the DB using the REV way?
The typical way to do this is to create the tables in PhpMyAdmin, use writeSchema() to write a schema for them, then use parseSchema to create all the class and map files that will let you use xPDO with them.
I did read other posts about using custom tables etc and it did seem rather complex for what was once a simple task. I know why this is the road with REV, it was stated in the posts I read. That was a nice simple solution to display tables from the database, is there a simple solution to INSERT tables as well?
Ross

Thanks for the replies.
Yeah it would be great to see a simplified tutorial for this, coming from the ease of EVO to REV has been a slight shock. I’ve never worked with PDO before and it’s exceptionally complex compared to what I’m use to. I have always manually created the tables in the database that I use my custom snippets with and used the EVO methods to send and retrieve the data, it was so straight forward. I guess there’s a lot of reading and frustration ahead
Looking forward to the tutorial Bob, I’m sure there’s a lot of us waiting... no pressure

I hope it’s as easy as that! What resources did you use to get yourself in-tune with it? Did you read the PDO manual for PHP or should the modx xPDO manual be enough?

