Question: I am quite new to PHP/MySQL and I would like to know whether it is possible to use a PHP function in a UPDATE statement, like this:

```
<?php
function myfun($a) {
   $a = $a + 1;
   return $a;
}

mysql_query("UPDATE `my_table` SET `myfield` = myfun(`par`)");
?>

```

Answer: 
no you can only do the following

[update mysql with php](http://www.w3schools.com/php/php_mysql_update.asp)

you could do the following tho

```
mysql_query("UPDATE my_table SET myfield = '".myfunction(par)."'");

```

or

```
$sql = "UPDATE my_table SET myfield = '".myfunction(par)."'";
mysql_query($sql);

```

**UPDATE**
is this what you mean?

```
updateTable(10);

function updateTable($num){
   for($i = 0; $i<$num; $i++){
       mysql_query("UPDATE my_table SET myfield = '".$i."'");
   }
}

```
No. No, it's not.

These are two independent and distinct technologies, implemented by two separate processes.

However, [you can define procedures in MySQL itself](http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html)...