Welcome Guest, Not a member yet? Register   Sign In
MySQL Inserting twice and not sure why
#6

[eluser]JamesD[/eluser]
[quote author="bapobap" date="1200010095"]I'm executing the SQL query in the library, so the object isn't accessible from the library (yes, I really don't understand OOP quite yet!).

I did try it in the controller using $this but it still happened, displayed once, in the profiler once but executed twice.

I think I'm going to give up, I think hooks might help me. I basically just needed this insert to be run with every single page request.

Thanks by the way![/quote]

Was there a particular reason why you set it up as a library instead of a model?
Don't think you'll have the problem if you were to set it up as a Model instead.

For example:

Code:
<?php

class Main_model extends Model {
    var $obj;

    function Main_model()
    {
        parent::Model();
        $this->obj =& get_instance();
    }

    function start_page()
    {
        $sql = 'INSERT INTO `site_requests` (`id`, `request`, `referer`, `ip`, `xip`, `type`, `user_agent`, `date`) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);';
        return $this->db->query($sql);
    }

?>

And use something similar to
Code:
$this->load->model('main_model', '', TRUE);
to load it.

-JamesD


Messages In This Thread
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 10:33 AM
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 10:49 AM
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 11:57 AM
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 12:03 PM
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 12:08 PM
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 12:24 PM
MySQL Inserting twice and not sure why - by El Forum - 01-10-2008, 02:29 PM
MySQL Inserting twice and not sure why - by El Forum - 01-11-2008, 10:45 AM
MySQL Inserting twice and not sure why - by El Forum - 01-11-2008, 11:10 AM
MySQL Inserting twice and not sure why - by El Forum - 01-11-2008, 03:02 PM
MySQL Inserting twice and not sure why - by El Forum - 01-11-2008, 03:28 PM
MySQL Inserting twice and not sure why - by El Forum - 01-12-2008, 01:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB