Page 1 of 1

adodb / adodblite and general sql question

Posted: Tue Jan 09, 2007 1:17 pm
by Luke
I have always used the REPLACE statement for replacing data in a mysql database, but to my knowledge, that is not available in other databases... so, I am now using adodb-lite, and I need to know... what do I do to get the same functionality, but without limiting myself to just mysql?

Are there comparable methods in other dbs?

Is this what people do?

Code: Select all

public function write($id, $data)
    {
		$deleteQuery = "
			DELETE FROM `" . $this->_sessionTable . "`
			WHERE `" . $this->_sessionTable . "`.`id` = ?
		";
		$this->_db->execute($deleteQuery, array($id));
		
		$insertQuery = "
			INSERT INTO `" . $this->_sessionTable . "`
			(id, user_id, user_ip, data, access)
			VALUES (?, ?, ?, ?, ?)
		";
		$values = array(
			$id,
			$this->_userId,
			$this->_remoteAddr,
			$data,
			time()
		);
		$result = $this->_db->execute($insertQuery, $values);
		return $result;
    }

Posted: Tue Jan 09, 2007 2:55 pm
by feyd
If memory serves, remove backticks and make sure the fields/tables aren't keywords. :)

Posted: Tue Jan 09, 2007 3:00 pm
by Luke
thanks feyd :)

any ideas on the replace functionality? is what I posted what most people do?

Posted: Tue Jan 09, 2007 3:17 pm
by feyd
Sorry, I missed that first go around.

From a quick look, REPLACE is MySQL specific, so DELETE & INSERT or UPDATE are the alternates.

Posted: Tue Jan 09, 2007 3:40 pm
by Luke
Cool, I just wanted to be sure that there wasn't anything wrong with delete/insert because update won't insert if the session isn't already created. Thanks! :D