skip to Main Content

In my Code Igniter (PHP) application I insert multiple rows using the query below:

INSERT INTO attribute_data (attribute_ID,product_ID,attribute_value) VALUES (2,3,123),(2,3,543)

The column named ‘attribute_value’ is set to 0 for both rows.

However, when I paste the query directly into phpMyAdmin it sets the column ‘attribute_value’ with the given numbers (123 and 543 in my example). So, my guess is that nothing is wrong with the query. But please correct me.

Probably not very helpful, but here is my Code Igniter code:

$sql = "INSERT INTO attribute_data (attribute_ID,product_ID,attribute_value) VALUES (2,3,123),(2,3,534)";
$this->db->query($sql);

Some info on what I’ve been looking at:

  • I’ve already tried using quotes although it’s an integer.
  • The ‘attribute_value’ column is not a primary key

UPDATE

I’ve enabled profiling. The query is the same in the profiling output.

UPDATE 2

I tried using the insert_batch() method with the same result. Records are still being added with 0 instead of the given value.

$this->db->insert_batch('attribute_data',$insert_data);

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for all your help. The acknowledgement of my code and the query being OK was enough for me to start thinking about caching.

    I checked out caching of MySQL first but this is taken care of out of the box. The Code Igniter caching was causing the problem here. Not the end solution of course, but below method helped me out a lot.

    $this->db->cache_delete_all();
    

    Once I delete the cache before inserting data, the correct values were inserted. So,the column attribute_value was in cache somehow. Now my quest continues to make it work with Code Igniter caching turned on.

    Thanks again, you rock!


  2. The above mentioned code is working fine. I think you have a database connection issue.

    Change the environment to development mode in index.php file

    index.php file is located in root folder of your project. Change the text production to environment.

    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : '`development`');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search