2

I'm working on an ExpressionEngine 3.5.10 website. All my tables are prefixed with exp_

I've added 3 tables to my database to store some data relating to a custom written PHP ecommerce module. These tables do not use the prefix, and are called: ecom_orders, ecom_attendees and ecom_products.

In one of my EE templates - with PHP set on output - I've written the following to try and insert data in one of my tables:

 ee()->db->insert(
        'ecom_orders',
        array(
            'billing_title'  => $_SESSION['basket']['billing']['title'],
            'billing_firstName' => $_SESSION['basket']['billing']['firstName'],
            'billing_surname' => $_SESSION['basket']['billing']['surname'],
    // ...
    ) );

The trouble with this is that I get an SQL error because instead of using the table name ecom_orders, it's changing it to exp_ecom_orders.

How can I reference the table by the name I want (ecom_orders) and get it to ignore the prefix?

I checked the database class docs https://docs.expressionengine.com/latest/development/legacy/libraries/database.html but there's nothing in it about that.

1 Answer 1

1

You should never use any table in EE without prefix. Its totally not recommended. Now you have only 1 possibility. Instead of using EE (CI) query, use sql.

ee()->db->query( "INSERT INTO `ecom_orders` (`billing_title`, `billing_firstName`, `billing_surname`) VALUES ('".$_SESSION['basket']['billing']['title']."', '".$_SESSION['basket']['billing']['firstName']."', '".$_SESSION['basket']['billing']['surname']."')");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.