#1
  1. No Profile Picture
    WannaKnow
    Guest
    Devshed Newbie (0 - 499 posts)
    Is there a way to include PHP3-functions or -procedures in a MYSQL-UPDATE-statement?
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Yes, sort of. How depends on what you are trying to do. (hint, hint)
  4. #3
  5. No Profile Picture
    moderator
    Guest
    Devshed Newbie (0 - 499 posts)
    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)."'");
    ?>
    [/quote]

    What exactly where you trying to do?
  6. #4
  7. No Profile Picture
    WannaKnow
    Guest
    Devshed Newbie (0 - 499 posts)
    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')";
    ======

    MyLib.php3:
    function myPHPfunction($field_1)
    {
    $field_1 = [... for example: several different commands to convert special characters ...]

    return $field_1;
    }

    ------------

    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.
  8. #5
  9. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    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.

    Rod

  10. #6
  11. No Profile Picture
    WannaKnow
    Guest
    Devshed Newbie (0 - 499 posts)
    Select, modify, update – that’s what I did now. Nevertheless, thanks for your help.

Similar Threads

  1. php mysql api functions - speed
    By bakedbean in forum PHP Development
    Replies: 0
    Last Post: December 11th, 2001, 10:40 AM
  2. How 2 install MySQL and PHP3 on Linux 6.1
    By eduany in forum PHP Development
    Replies: 1
    Last Post: March 15th, 2000, 07:23 AM
  3. Replies: 1
    Last Post: July 17th, 1999, 04:10 PM
  4. Replies: 0
    Last Post: July 16th, 1999, 11:15 AM
  5. Replies: 0
    Last Post: July 16th, 1999, 11:08 AM

IMN logo majestic logo threadwatch logo seochat tools logo