I want to use my custom PHP function CalculateAge which takes 3 parameters (day, month and year) inside a SQL UPDATE. However, I need to pass the SQL variables to the function, and I don’t know how to do it. Here’s what it looks like (note that bday, bmonth and byear are “users” table columns).
mysql_query("UPDATE users SET age=".CalculateAge(bday,bmonth,byear)."");
You can’t pass the mysql values into the function like that. You would have to do a
SELECTto get the values, fetch the row, pass them into the function, and thenINSERTthat value.I would suggest that instead of updating the age, you should store the person’s birthday since it never changes. When you want to show their age, just do the math.