The Coder

Write SQL Function

Original posted by: Admin on 28-01-2007

This function has been written to help better manage SQL queries that alter the database in anyway, such as insert or update queries.

It's fairly simple and can save a lot of time if used constantly.


function writeDB($query) {
mysql_query($query) or die(mysql_error());
return mysql_insert_id();
}


It's a simple query and is very simple to use, simply send it a mySQL query and it will process it, if its an insert query it will send back the new rows primary key value.


$insert_id = writeDB('INSERT INTO `foo` (`col1`, `col2`, `col3`) VALUES ("value1", "value2", "value3")');




Login to make a comment 0 Comments Found