failed to open stream Error

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

User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: failed to open stream Error

Post by jackpf »

Are you including the file twice?

Put "echo 'included';" or something in database.php, and see how many times it's output.

If you really can't find it, try using include_once() instead of include().
pathfinder
Forum Newbie
Posts: 10
Joined: Thu Aug 06, 2009 7:14 am

Re: failed to open stream Error

Post by pathfinder »

Hi
When echoing included, it return two times

Code: Select all

 
Include
Include
 
And when I am use
function MySQLDatabase()
{ echo MySQLDatabase();
}
to find the location (may be i am wrong...) of declaration it returns,

Code: Select all

 
Fatal error: Cannot redeclare mysqldatabase() (previously declared in J:\wamp\www\photo_gallery\includes\database.php:5) in J:\wamp\www\photo_gallery\includes\database.php on line 6
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: failed to open stream Error

Post by jackpf »

Then you're including it twice. You should only include it once. Find where you're including it the second time, and remove that code.
pathfinder
Forum Newbie
Posts: 10
Joined: Thu Aug 06, 2009 7:14 am

Re: failed to open stream Error

Post by pathfinder »

Hi
will u tell me how to find second "include"
any function of procedure...........
other wise i will manually find....
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: failed to open stream Error

Post by jackpf »

You need to look through your code.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: failed to open stream Error

Post by superdezign »

An alternative is to use the include_once() directive instead of include().
Always use include_once() when including files with class definitions.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: failed to open stream Error

Post by jackpf »

Well...if the include is in a function which is called multiple times then yeah....

But it seems as though the OP is including the file twice accidentally. That's just....bad code, and shouldn't be covered up with include_once(). He should find out where the extra unneeded include is and remove it.

Besides, include_once() is slower than include(). Not that you could even tell...but that's what I've heard :P
Post Reply