The problem:
PHP Code (no framework)
if ($this->uid)
{
$query = sprintf('UPDATE %sUSER SET USERNAME = "%s", ' .
'PASSWORD = "%s", EMAIL_ADDR = "%s", IS_ACTIVE = %d ' .
'WHERE USER_ID = %d',
DB_TBL_PREFIX,
mysql_real_escape_string($this->username, $GLOBALS['DB']),
mysql_real_escape_string($this->password, $GLOBALS['DB']),
mysql_real_escape_string($this->emailAddr, $GLOBALS['DB']),
$this->isActive,
$this->userId);
mysql_query($query, $GLOBALS['DB']);
}
else
{
$query = sprintf('INSERT INTO %sUSER (USERNAME, PASSWORD, ' .
'EMAIL_ADDR, IS_ACTIVE) VALUES ("%s", "%s", "%s", %d)',
DB_TBL_PREFIX,
mysql_real_escape_string($this->username, $GLOBALS['DB']),
mysql_real_escape_string($this->password, $GLOBALS['DB']),
mysql_real_escape_string($this->emailAddr, $GLOBALS['DB']),
$this->isActive);
mysql_query($query, $GLOBALS['DB']);
$this->uid = mysql_insert_id($GLOBALS['DB']);
}
Kohana Code (using ORM)
public function save()
{
$query = ORM::factory('user', $this->user->uid);
if ($this->user->uid) :
$query->username = $this->user->username;
$query->password = $this->user->password;
$query->email_addr = $this->user->emailAddr;
$query->is_active = $this->user->isActive;
else:
//????????
}
Will I go about creating the same mysql_insert_id when I don't even know if it was an insert or an update the ORM performed? Or is there another way to know the id of the last insert operation?