September 27th, 1999, 10:41 AM
Is there a way to include PHP3-functions or -procedures in a MYSQL-UPDATE-statement?
September 27th, 1999, 01:21 PM
Yes, sort of. How depends on what you are trying to do. (hint, hint)
September 28th, 1999, 12:34 PM
It is fine if you wanted to do something like this:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
mysql_query("SELECT * FROM tableName WHERE id='".customPhpFunction($var)."'");
What exactly where you trying to do?
September 29th, 1999, 06:15 AM
Thank you for your quick reply. Ok, here are some more details: I want to update all records in a table at the same time with an update-statement, which should look like this:
UPDATE tableName SET field_1=myPHPfunction('$field_1')";
$field_1 = [... for example: several different commands to convert special characters ...]
Although the PHP3 manual states that UDFs must be written in C or C++ and the opereating system must support dynamic loading (under point 14.1) I hope there is a way to realize a.m. example. I know from other programming languages as FoxPro for Windows that you can include „foreign“ functions into an SQL-statement. I tried above UPDATE statement in several different ways but it didn’t work.
September 30th, 1999, 03:56 PM
UDF's need to be in C, but you can include functions written in php in your script directly or by including or requiring an external file. UDF's become a part of the language itself.
I just reread your post. Are you trying to have a query read the field and modify it based on that read?
That can't be done with one query. That's a limitation of MySQL, not PHP. Sorry.
Just a note: The latest versions of MySQL DO allow INSERT ... SELECT statements. Unfortunatly, the table(s) referenced in the INSERT cannot appear in the SELECT. I don't believe any SQL engine allows what you are trying to do.
Why not just use two queries? Select, modify, update.
October 7th, 1999, 11:03 AM
Select, modify, update – that’s what I did now. Nevertheless, thanks for your help.