[Typo3-dev] mysql_connect, mysql_affected_rows and mysql_insert_id in same context in multi-user environment?

Dennis Petersen fessor at software.dk
Mon Jul 28 21:36:33 CEST 2003


Hi there..
In my intimate lack of knowledge about PHP connections in MySQL I have to
ask this question as what I am doing could be dead wrong (I'd say dangerous,
but hey this isn't rocket science) - sorry if it is too much a newbie like
question...:

When implementing a new frontend plugin that will insert records into the
database I came across the need to use the functions mysql_connect,
mysql_affected_rows and mysql_insert_id.

Suddenly I am gripped with fear that I am not using them correctly when I
looked them up in the reference (www.php.net)

In the reference it is not explained clearly how the functions are actually
ensured to work in the same context which is extremely important in
multi-user environments since if they are not run in the same context one
user might make either mysql_affected_rows or mysql_insert_id return wrong
values... HELP!

Is there a specific way to use these function within Typo3 that ensures that
they run in the same context?

Here I have an example of a function that I implemented which may contain
problems in a multi-user environment...

 function insertRecord($query) {
  $returnVal = array();
  print_r(TYPO3_db);
  $res = mysql(TYPO3_db,$query);
  if (mysql_error()) {
   $arr_mysql_error = array(mysql_error(),$query);
   // Actually I want it to send me an email... TODO
   debug($arr_mysql_error);
   $returnVal[0] = -1;
   $returnVal[1] = arr_mysql_error;
  } else if (mysql_affected_rows($res) > 0) {
   // Went great so returning the AUTO_INCREMENT ID for use when inserting
in other tables...
   $returnVal[0] = mysql_insert_id($res);
   $returnVal[1] = array("", $query);
  } else {
   $arr_mysql_error = array($this->getLL("unknow_error", "An unknown error
has occurred"), $query);
   // Actually I want it to send me an email... TODO
   debug($arr_mysql_error);
   $returnVal[0] = -1;
   $returnVal[1] = $arr_mysql_error;
  }
  return $returnVal;
 }


Please ease my worries...
Sincerely,
Dennis Petersen (fessorman)






More information about the TYPO3-dev mailing list