Jump to content

Archived

This topic is now archived and is closed to further replies.

yaron160

I need help! ...whierdest problem ever!

Recommended Posts

hi there.
I have recently upgraded my server to a 64bit intel system.
I've changed from php 4.3.2 to php 5.2.1.
Also from mysql 4.1.10 to mysql 5.0.19 (64bit version)
Also from IIS 4 to IIS 6, and I'm now working in a win server 2003 x64 edition.

A script I wrote and worked perfectly on the previous system doesn't work now.
Basicly the script updates a database according to some directories and filesystem structure.

I managed to narrow down to the part of the code where the problem exists.
It seems to me there is some kind of a conflict between the mysql and php.

here is the code:

[i]//connecting here to the mysql server[/i]
$dbname = "example";
$conn = mysql_connect("localhost","root","rootpassword");
if (!$conn) die("can't establish a connection to the sql server");
if (!mysql_select_db($dbname,$conn)) die("can't find the database '$dbname'");


[i]//this is a part of a recursive function I use to scan all the last directories in the directory's hirarchey
//and if the directory isn't in the database... add it.[/i]

chdir($path);
$dp = opendir($path);
while (false !== ($file = readdir($dp))) {
if (is_dir($file)) {
if (($file != '.') && ($file != '..')) {
$i = check_next("$path/$file");
// check_next is a function that returns the number of directories inside a directory.
chdir($path);
if ($i == 0) { //if there are no directories in this one ....
$i2++; //just some count var I use. take no notice!
//the following 2 lines are handling $str.
//I've checked them. this isn't what's causing the problem!
//I know this, because I've made my script echo it, and made sure it is correct for every case.
$str = substr("$path/$file/",$cut+1);
$str = str_replace("'","\'",$str);
//this is where the problem is!
if (!exists_in_table("table","field","dir_parent='$i1' and dir='$str'")) {
echo $i1.'-'.$str.'<br>'; //this is just a test line I've added.
// ... and so on!
}

//the function 'exists_in_table' does this:

function exists_in_table($table,$fields,$conditions) {
global $conn;
$bool = true;
$sql = "select $fields from $table where $conditions";
if (!$result = mysql_query($sql,$conn)) die(mysql_error());
if (mysql_num_rows($result) === 0) $bool = false;
return $bool;
}

//NOTE!
-this code worked in the past.
-I know that there is no problem with the query!
-I'm not using a 'latin1' charset in mysql. I don't think, though, this is what's causing the problem.
I've done some tests, and this is what I've found:
- not all, but only some of the directories can't be found in the mysql query, even though they exist!
(the mysql_num_rows == 0).
- when I have added manually a test query before the 'if' line, I did get resaults, except when I was
reading that directory.
(this is the test query I have added:

$sql = "select field from table where dir_parent='40' and dir='the dir name'";
if (!$result = mysql_query($sql,$conn)) die(mysql_error());
if (mysql_num_rows($result) == 0) echo 'Couldn\'t find it!<br>';
else echo 'Found it<br>';

)
(this is its output:

...
Found it!
Found it!
Found it!
Couldn't find it!
40-the dir name
Found it!
Found it!
Found it!
...
)



If anyone have any idea as of how to overcome this... without compleatly rewriting the code around this... please tell me!
I have no more ideas left.

Thanks...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.