Log in

View Full Version : PHP script doesn't update properly a MySQL table



agoia2000
05-14-2006, 05:39 PM
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?

Twey
05-14-2006, 06:21 PM
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.

agoia2000
05-14-2006, 06:30 PM
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 ***

Twey
05-14-2006, 06:37 PM
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.

agoia2000
05-18-2006, 12:07 PM
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:)