tags:

views:

121

answers:

9

Hello;

A PHP application that was working perfectly on a LAMP server can't require or include files at all after migrating to a Windows Server 2003 machine. For example, given the following file :

   include("connectme.php");
  echo "==== $SERVER_NAME, $USER, $PASSWORD";
  $sql="SELECT id, model
FROM `products`
WHERE acc_code IS NULL
OR acc_code =0";
  $prodset=mysql_query($sql);


  while($prod=mysql_fetch_array($prodset,MYSQL_ASSOC))
  {
      echo $prod[id].",".$prod[model]."<br>";
  }

The file will fail with a MySQL connection error, although the connection parameters are specified in the included connectme.php file. If I comment the include line and hard-code the connection parameters, it works.

Any ideas?

Thanks

Update: in the connectme.php connection parameters are defined and given values. But for some reason, the variables aren't visible in the including files scope. When I adding a line to echo the variables $SERVER_NAME, $USER, $PASSWORD all were empty.

A: 

I don't know what your directory structure is, but have you tried relative paths as a test?

If it is in the same directory:

include(".\\connectme.php");

???

Mark S.
Both files are in the same folder on the Windows server.
A: 

Here's something to look out for: slashes in windows go in the other direction, and there are also issues with newlines. Try other sanity tests, like including files that do echo to determine the directory structure and etc.

Extrakun
Windows itself recognizes / as a path separator character, and has since at least Windows NT 4.0 in the mid-90s.
R. Bemrose
A: 

Check the permissions on the included file. You will need to allow access for the IUSR account to read and execute. You should be able to access the file as an include once you've done this.

Zenham
A: 

This is almost certainly an include_path issue. You can set it in a bunch of ways.

You can create a page with

<?php phpinfo(); ?>

in it to view the current include path. You can change it with ini_set in your page, in the php.ini configuration file, or in your .htaccess file if you're using Apache.

You can see more here:

http://us2.php.net/configuration.changes

Rafe
A: 

I'd replace the include by require since it's not optional for your script and it's not a mere configuration error if the file is not present.

require "connectme.php";

This connectme.php contains the mysql_connect and mysql_select_db()? Then add at least some basic error handling to the connect-code and make it possible to access the mysql link resource. Absolute minimal version

<?php
$mysql = mysql_connect('...', '...', '...') or die(mysql_error());
mysql_select_db('...', $mysql) or die(mysql_error());

And then use this link resource and also add error handling to mysql_query. Again, minimal version

$prodset=mysql_query($sql, $mysql) or die(mysql_error());
VolkerK
A: 

Maybe some configuration are overwriting the default include path for php, to ensure that the current dir are in your include_path you can try this:

set_include_path(get_include_path() . PATH_SEPARATOR . ".");
Nathan
both files are in the same folder.
Yes, but if in the php.ini the include_path hasn't a "." (dot) it will not include the files from the current dir without specifying the entire path.
Nathan
Include path has **.** : .;C:\php5\pear
Can you show your connectme.php file? Also, to make sure that php is including your file try: echo file_get_contents("connectme.php");A die() on the connectme.php file also works.
Nathan
A: 

You pass a relative path to include(). It's relative to the current working directory. Maybe the cwd isn't what you expect it to be. Some extra debug output can clarify that.

<?php
echo '<div>Debug: __FILE__=', __FILE__, '</div>';
echo '<div>Debug: cwd=', getcwd(), '</div>';
echo '<div>Debug: glob(*.php)=', join(', ', glob('*.php')), '</div>';
require "connectme.php";
VolkerK
A: 

what happens if you copy the content of connectme.php into the main file?

just guessing: could be some issue due to the different end line between linux and windows?

dam
It works without problems.If your assumption is true, how can I solve that?
I'm not so sure it's about the end line. I bet on some issue on path but you can try to exclude it. In a bash console try this:cat file.ori.php | sed 's/$'"/`echo \\\r`/" > file.win.phphere a complete and awesome guide to sed<http://sed.sourceforge.net/sed1line.txt>
dam
+1  A: 

Hi!

It turned out that some files (the connectme.php included) use short tags <? ?>, and since the server is a new server with a fresh PHP install (in which the short tags aren't enabled by default) it included the entire source of connectme.php without interpretation. Quite elusive!

Thanks all for your help!