adodb / adodblite and general sql question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

adodb / adodblite and general sql question

Post 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;
    }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If memory serves, remove backticks and make sure the fields/tables aren't keywords. :)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

thanks feyd :)

any ideas on the replace functionality? is what I posted what most people do?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
Post Reply