• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PostGreSQL $this->db->insert_id()

#1
[eluser]Greg Aker[/eluser]
Hey guys,

I have run into a problem with postgres 7.4.7 and getting the insert_id properly returned. I came up with a workaround, but it's not going to work with php4.

I thought I'd share my findings and see if anyone can add to it.

./system/database/drivers/postgre/postgre_driver.php

_version()

was not working for me. a var_dump or print_r gave me the value of "S".

so I changed it to:

Code:
function _version()
{
    return pg_version();
}

So that is where the php4 vs php5 issues come in to play.

Then, in the MSSQL driver, there is a function to grab the major version. I used a modified version of that to give me the major and minor version, and this is what I came up with.

Code:
function _parse_version($version)
{
    $v = $version['server'];

    preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $v, $ver_info);
    $ver = $ver_info[1] . '.' . $ver_info[2];
    return $ver;
}

The I changed the top of insert_id() to:

Code:
function insert_id()
{
    $v = $this->_parse_version($this->_version());

So that's what I have and it's working nicely for me on pg 7.4.7. I'd like to see what you guys think, and I appreciate any feedback.

Thanks,

-greg


Messages In This Thread
PostGreSQL $this->db->insert_id() - by El Forum - 09-10-2008, 02:53 PM
PostGreSQL $this->db->insert_id() - by El Forum - 09-10-2008, 03:45 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.