ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Custom PHP calls to data within EE

January 04, 2012 5:15pm

Subscribe [3]
  • #1 / Jan 04, 2012 5:15pm

    bdcads

    30 posts

    Greetings!

    We’re trying to figure out how to properly read/write/update data to/from EE via an outside script. I’ve looked at the API, but it doesn’t seem like those examples directly pertain to what we’re after. For example, we’d want to maybe search a particular channel to see if a $str exists in a certain column within that channel.

    Currently, the site is being structured with expression engine and playa, for relational data content. I was wondering if it is possible to pull data from the channel entries using direct php and mysql statements instead of using expression engine tags and templating system.

    Right now we’re a little lost. Any direction at all is welcomed. :down:

  • #2 / Jan 05, 2012 3:04am

    ahmad saad

    364 posts

    To search a $str exists in a certain column within that channel you can use search parameter.

    If you want to use your sql you can use Query module

  • #3 / Jan 05, 2012 3:22pm

    Dan Decker

    7338 posts

    Hi bdcads,

    Welcome to the Forums!

    While what you are asking is technically possible, it is certainly a bit unorthodox. Making changes to dat inside ExpressionEngine’s tables from outside of EE could wreak havoc on ExpressionEngine. What I would like to ask is what your end-goal is? What kind of external site/service are you looking to integrate with ExpressionEngine? We would certainly like to help you achieve that, but there may be a way to do it using EE, rather than trying to go around it. Give me a little more context and I’ll be happy to offer some suggestions.

  • #4 / Jan 05, 2012 6:37pm

    bdcads

    30 posts

    Thanks guys.

    We plan to use CartThrob to handle e-Commerce for our client, and they have various ordering types. Some of them are physical or digital goods, and others are subscription in nature. We need the ability to manage the automatic handling of these orders in EE after the order is complete. I’m hoping to automate pieces of post-order handling so that the client’s staff doesn’t need to.

    A good example would be a paid listing of sorts. We can have the user include the details of their listing (title, short description, body, URL, etc) via custom fields on the ordering page, and after CartThrob handles the order, it’s my understanding that the following file will allow us to do more after we get approval for an order from the gateway:

    system/modules/cartthrob/process/cartthrob.on_authorize.php

    After the order’s completed, I’d like to put rules into that file to manipulate data within EE with PHP, such as adding a new row to a channel called “listings”. There’s more to it than that, but this is probably the easiest example I can give. My end goal was to definitely NOT have PHP working directly with MySQL….for the same reason I wouldn’t want to do that in Wordpress.

    If there’s a way to do this with the API(s) that I haven’t yet seen, I’m all ears. Getting this basic communication functionality down between custom PHP and EE is paramount to our being able to do more with our clients project and others later on.

    I appreciate your help!

    Thanks,
    Will Ashworth

    PS - We may also want to do some things later via cron as well, which I haven’t fully looked into, but having my PHP communicate with EE in the way we’re talking about right now will affect those types of scripts later as well. Maybe they’ll be reports, etc….not sure yet.

  • #5 / Jan 06, 2012 5:24pm

    Dan Decker

    7338 posts

    Hey Will,

    The good news is, there are sanctioned way to extend both ExpressionEngine and CartThrob. You have already been over the Channel API, so that is the recommended path for adding entries to a channel.

    My suggestion would be to look at writing an EE extension that is called via CartThrob’s hooks and uses the Channel API to add your entries. You would be using MySQL via PHP, but through ExpressionEngine’s underlying Codeigniter Framework.

  • #6 / Jan 06, 2012 11:32pm

    bdcads

    30 posts

    Okay, I’ll take another look at the API. Adding I get, but the editing seemed limited. I wasn’t sure about “editing” specifically, since it looked like I needed to know specific ID’s for the row(s) I’d want to edit. I didn’t see any way to do a search, which would let me essentially find the ID so I know what to pass through to the API. Granted, I’m new to this particular framework (but not CI), so it will probably get simpler once I understand how EE is structured a bit better.

    MySQL queries to find/narrow data results I can do. I just haven’t figured out how to do it with EE yet. The examples are slim from all the searching I’ve done. Like I mentioned before, maybe I’ve been looking in the wrong places being new to EE.

  • #7 / Jan 10, 2012 7:22pm

    Dan Decker

    7338 posts

    If you got some chops in SQL, you can use all that inside ExpressionEngine. EE supports all the features of CI 2.0. When you develop an add-on, you get the instance of the EE Super Object, which then hand off to CI. So if you are accustomed to:

    $this->db->function();

    In EE, it would be:

    $this->EE->db->function();

    Remember, in its heart, ExpressionEngine is just a Codeigniter app and you should be in good shape!

    Cheers!

  • #8 / Jan 10, 2012 7:37pm

    bdcads

    30 posts

    The concern I had was maybe not using SQL queries, thinking that EE handled relational storage across multiple tables similar to how Wordpress would do it…you simply don’t do that, and use their functions instead so that data ends up in the right place.

    Another example, is that our channels appear as a “table” in EE with many rows and columns, but there isn’t necessarily a MySQL table with the same name and structure as a channel. That said, if I use SQL queries with the $this->EE example, would I be querying the behind-the-scenes MySQL tables, or would I be querying an interpreted version of data that EE’s already scrubbed.

    Sorry, it’s really had to articulate what I’m thinking about this subject in writing. I’m probably confusing you with what I’m asking 😊

    For example, I cannot do this, can I?

    SELECT * FROM channel_name_here WHERE title = 'Some Title Here'

    The channels don’t have a MySQL structure that matches what we see in the EE GUI, so I was wondering how we’d handle the more advanced queries like that. If we can figure this out so I can safely use MySQL queries, we’re golden. I’ve been developing web applications for 11 years and know it well.

  • #9 / Jan 16, 2012 7:10pm

    Robin Sowell

    13255 posts

    Particularly for adding or editing an entry, if you can possibly use the API, that will be the way to go.

    thinking that EE handled relational storage across multiple tables similar to how Wordpress would do it…you simply don’t do that, and use their functions instead so that data ends up in the right place.

    And you’re exactly right.  Particularly w/Playa in the mix- I’ll admit I’m not sure how that’s stored, but the entries API SHOULD make sure that custom field types are handled correctly.

    Now- that’s not to say you can’t use a mix of custom php/mysql and API’s- and indeed it sounds like you might want/need to.  So use mysql to find the relevant entry_id and then the API to update that entry.  And Carthrob products are already associated with EE entries- right?  Isn’t the entry_id available already in some way/shape/form?  Or is it a matter of wanting to find OTHER entries- perhaps those associated via playa?

    Hrm- sorry I’m vague.  I’m just not totally up on either Cartthrob or Playa’s db structure.  But I suspect what you want to do should be fairly easy using custom queries (see CI’s database class) and the EE API.  Well, for a given value of easy. 

    If you want to walk me through what you’re trying, I’m happy to chime in on specifics.  But you’ll likely need to lay out a lot of the data structure in CT and Playa.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases