Results 1 to 5 of 5

Thread: PHP script doesn't update properly a MySQL table

  1. #1
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP script doesn't update properly a MySQL table

    Hello everybody!

    Here is my setup:
    - OS: WinXP pro
    - Apache 2.0.54 server
    - PHP 5.0.4
    - MySQL 4.1.12a-nt

    I wrote a PHP script who scans a table (let's call it tbl_0) and, after performing some calculations, inserts about 15,000 rows of data into another table (let's call it tbl_1).

    Verifying data in tbl_1, I was surprised to see that some (but not all) of the fields were not updated as expected (e.g. I saw empty fields where definitely they supposed to be non-empty).

    I've moved my script and tables to a Linux computer and this time everything was fine, the script does its job.

    I have serious reasons to work in Windows environment, so this "trick" is not an option for me.

    Anyone can help? It seems to be an implementation problem, is there a patch or a setup who will make things work well alltogether?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I can't really help without seeing your script (passwords and other sensitive data removed, of course).
    Generally speaking I'd say to try:
    a) echo()ing all the queries to make sure they're being executed as you expect them to be, and
    b) using another version of MySQL; 5.1.7_beta is pretty stable now, I think (it's made it into Portage, at least).

    If the above two options done
    I have serious reasons to work in Windows environment, so this "trick" is not an option for me.
    What reasons? Maybe we could overcome those.
    Also, hosting and/or testing in a Linux environment doesn't mean you can't work in a Windows environment.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you Professor,

    Here is the core of the script:
    *** begin ***

    $qry=mysql_query("SELECT grupa, cod_alt, cod_org FROM tbl_0 WHERE cod_alt<>'' AND cod_org<>''") or die("15");
    while ($row=mysql_fetch_array($qry, MYSQL_NUM))
    {
    $grupa=$row[0];
    $cod_alt=$row[1];
    $cod_org=$row[2];
    $qry1=mysql_query("SELECT marca, tip, familia, model, praf_asociat FROM tbl_0 WHERE cod_org='$cod_org' and model<>''") or die("21");
    while ($row1=mysql_fetch_array($qry1, MYSQL_NUM))
    {
    $marca=$row1[0];
    $tip=$row1[1];
    $familia=$row1[2];
    $model=$row1[3];
    $praf_asociat=$row1[4];
    $qry2=mysql_query("INSERT INTO tbl_1 VALUES ('$marca', '$tip', '$grupa', '', '$cod_org', '$cod_alt', '$praf_asociat', '$familia', '$model', '1')") or die("28");
    // echo "st1 $marca, $tip, $grupa, $cod_org, $cod_alt, $familia, $model <br>";
    }
    }
    *** end ***

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Oh, well done!
    That's some surprisingly nice code, such as we don't often see around here

    However, I fear I see no obvious problems. Are there any other differences in environment between the Windows machine and the Linux machine? Different versions of MySQL or PHP, perhaps? It would indeed seem to be a bug.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've solved (or rather circumvented) the problem, this way:

    Instead of launching the script via browser:
    http://127.0.0.1/superscript.php

    I've launched the script at command prompt:
    c:\>php -f superscript.php

    Thanks the Lord, because I had a deadline for my precious works

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •