PHP and MySQL - odd behaviour

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

PHP and MySQL - odd behaviour

Post by Jean-Yves »

Just came across a bizarre phenomenon (to me at least), when testing some new PHP pages.

On my local dev PC (Win2K, IIS, MySQL 3.x), the page was displaying correctly. On my live system (Red Hat 7, Apache 1.3.x, MySQL 3.x), the database was not returning anything. Running the queries through phpMyAdmin showed that they were not to blame.

Took me ages to notice that I had forgotten to call my include file that contains all the connection code to link to MySQL. Quite rightly, the live system therefore decided that no connection was possible.

I'm puzzled as to why it should be working on the Windows box though. Does the windows version of PHP try to make a connection if it cannot find one, and search available databases until it finds an appropriate table? If so, can this be switched off in PHP.INI as it constitutes a huge data-integrity risk.

Thanks,
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

nope, php does no such thing, even if it could it would need a username/password to connect.

it was/is prolly cos of the path to include file. check that.
User avatar
Rook
Forum Newbie
Posts: 10
Joined: Thu Aug 21, 2003 10:40 am
Location: Euless, Tx.
Contact:

Post by Rook »

You need to make sure your file is in the include path on your Linux box, or implicitly set the include path in your script:

Code: Select all

<?php
ini_set(include_path, "/home/apache/htdocs/includes");
?>
- Rook.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

you need to get a better dev. there's differences between the operating systems that can cause issues.

you should make your dev and deployment environments be the same. you're using a LAMP deployment, you should have a LAMP dev
User avatar
Rook
Forum Newbie
Posts: 10
Joined: Thu Aug 21, 2003 10:40 am
Location: Euless, Tx.
Contact:

Post by Rook »

I have the same mis-fortune as Jean-Yves... I have to do my dev work on a W2k box.. but I'm at least running Apache. I've had very good success in writing code that runs good on both.

Sometimes you've got to work with what you've got!

- Rook.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://de.php.net/mysql_query
resource mysql_query ( string query [, resource link_identifier])
...
If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it.
If this happens (and succeeds) depends on your php/mysql configuration and the query.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

m3rajk wrote:you need to get a better dev. there's differences between the operating systems that can cause issues.
Yes, but you could if you want to learn, fix it so it works on all platforms. I personally loose to many potentional customers if I write something for *nix only, and I bet that so thinks most of the mayor proffessionals.
That is pershaps of course not true in your case.
m3rajk wrote: you should make your dev and deployment environments be the same. you're using a LAMP deployment, you should have a LAMP dev
That part is very true. If you are an serious freelancer working at home and dont feel/have the time to make it a dualplatform safe code, you could use a server with dualboot...
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

Thanks for all the replies.

I use Win2K cos that's what my office laptop is and I use it at home to develop. The live system is not a commercial site (it's my own site that runs a multi-user game for me and my friends) so there is no great concern regarding potential customers! :)

I actually do some of the development on an eComstation box (OEM version of OS/2 Warp 4 Server for eBusiness), and also on my home XP box on which I run Apache. This seemingly mad approach has enabled me to learn a lot more about the underlying technologies and how they interact (or not!), which to me is a good thing. Obviously, if I were developing a commercial site, I would replicate the live environment as closely as I could on my dev PC. This is what I do with the ASP and ColdFusion sites that I (and my team - can't take all the glory ;) )have written for clients.

Volka, I think that your explanation:
If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it.
almost certainly explains the behaviour that I encountered.

Anyway, thanks again for all the replies.

Jean-Yves
Post Reply