More include issues

This is a discussion on More include issues within the PHP General forums, part of the PHP Programming Forums category; Dan Shirah wrote: > Yes, I have error_reporting = E_ALL and show_warnings = On. > > Here's something interesting...if I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #21 (permalink)  
Old 06-06-2007
Stut
 
Posts: n/a
Default Re: [PHP] More include issues

Dan Shirah wrote:
> Yes, I have error_reporting = E_ALL and show_warnings = On.
>
> Here's something interesting...if I put the include directly above the
> code for the dropdown it works....like below:


<snip>

> and then the code stops again at the next area of my page where it needs
> to connect to the database.
>
> Since I have my database connection set as mssql_pconnect(persistent
> connection) I should not have to include the connection file before
> every attempt to retrieve something from the database, but that is the
> only way it is working right now.


Ok, first of all that's not what persistant connections are. Persistent
connection refers to pooling connections in the server such that each
page request does not need to create a new connection if an existing
idle connection exists.

I have no idea what's going on. It's possible that MSSQL is closing the
connection for some reason, but I really don't know. I suggest you
consult the MSSQL logs for clues.

-Stut
Reply With Quote
  #22 (permalink)  
Old 06-06-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] More include issues

On Wed, June 6, 2007 3:24 pm, Dan Shirah wrote:
> Yes, I have error_reporting = E_ALL and show_warnings = On.


Use phpinfo to confirm that, because...

> Here's something interesting...if I put the include directly above the
> code
> for the dropdown it works....like below:


> and then the code stops again at the next area of my page where it
> needs to
> connect to the database.


This sounds like a clear indicator that the problem is in your connect
script.

Aside: Having "../../" as part of the include path is a Warning Signal
for all kinds of settings, including open_basedir restirctions, and
also means you aren't leveraging include_path as you probably should.

> Since I have my database connection set as mssql_pconnect(persistent
> connection) I should not have to include the connection file before
> every
> attempt to retrieve something from the database, but that is the only
> way it
> is working right now.


That's NOT what persistent means at all...

PERSISTENT means:
"MySQL keeps my connetion around so it doesn't have to build a whole
new one the next time I connect"

It does NOT mean:
"I don't have to connect again"

PS
I also wouldn't recomment display_errors ON, but, rather, error_log ON
and make sure you can cause an error on purpose and read the error you
expect to see in the log file.

display_errors ON is only going to lead to trouble in the long run,
even on a dev box, with HTML masking errors and JS hiding erros, and
CSS not written to display errors leading to overlaid error output on
top of exected output, which makes both unreadable, and often
un-selectable for copy/paste without using "View Source"...

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
Reply With Quote
  #23 (permalink)  
Old 06-06-2007
Dan Shirah
 
Posts: n/a
Default Re: [PHP] More include issues

I thought that if you made a connection at the beginning of a page, that you
could use that connection throughout the page without having to type it over
again as long as you did not explicitly put in code to close the
connection?? Which is why I only inserted the include fil at the beginning
of the page.

Instead of having:

$connection = mssql_pconnect('SERVER','user','password') or die ('server
connection failed');
$database = mssql_select_db("database", $connection) or die ('DB selection
failed');

in my include file, I should only have $connection instead and then specify
$database before the query to the database.

Does that sound like the correct solution?

On 6/6/07, Richard Lynch <ceo@l-i-e.com> wrote:
>
> On Wed, June 6, 2007 3:24 pm, Dan Shirah wrote:
> > Yes, I have error_reporting = E_ALL and show_warnings = On.

>
> Use phpinfo to confirm that, because...
>
> > Here's something interesting...if I put the include directly above the
> > code
> > for the dropdown it works....like below:

>
> > and then the code stops again at the next area of my page where it
> > needs to
> > connect to the database.

>
> This sounds like a clear indicator that the problem is in your connect
> script.
>
> Aside: Having "../../" as part of the include path is a Warning Signal
> for all kinds of settings, including open_basedir restirctions, and
> also means you aren't leveraging include_path as you probably should.
>
> > Since I have my database connection set as mssql_pconnect(persistent
> > connection) I should not have to include the connection file before
> > every
> > attempt to retrieve something from the database, but that is the only
> > way it
> > is working right now.

>
> That's NOT what persistent means at all...
>
> PERSISTENT means:
> "MySQL keeps my connetion around so it doesn't have to build a whole
> new one the next time I connect"
>
> It does NOT mean:
> "I don't have to connect again"
>
> PS
> I also wouldn't recomment display_errors ON, but, rather, error_log ON
> and make sure you can cause an error on purpose and read the error you
> expect to see in the log file.
>
> display_errors ON is only going to lead to trouble in the long run,
> even on a dev box, with HTML masking errors and JS hiding erros, and
> CSS not written to display errors leading to overlaid error output on
> top of exected output, which makes both unreadable, and often
> un-selectable for copy/paste without using "View Source"...
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>


Reply With Quote
  #24 (permalink)  
Old 06-06-2007
Stut
 
Posts: n/a
Default Re: [PHP] More include issues

Dan Shirah wrote:
> I thought that if you made a connection at the beginning of a page, that
> you could use that connection throughout the page without having to type
> it over again as long as you did not explicitly put in code to close the
> connection?? Which is why I only inserted the include fil at the
> beginning of the page.
>
> Instead of having:
>
> $connection = mssql_pconnect('SERVER','user','password') or die ('server
> connection failed');
> $database = mssql_select_db("database", $connection) or die ('DB
> selection failed');
>
> in my include file, I should only have $connection instead and then
> specify $database before the query to the database.
>
> Does that sound like the correct solution?


The way you have it at the moment should work fine. Might I suggest you
try using a non-persistant connection? I've heard things in the past
that the persistant connection implementation in the MSSQL extension can
be a bit flakey.

-Stut
Reply With Quote
  #25 (permalink)  
Old 06-06-2007
Dan Shirah
 
Posts: n/a
Default Re: [PHP] More include issues

It seems that PHP is getting confused unless I post the $database =
mssql_select_db("database", $connection) or die ('DB selection failed');
before the query. This is probably due to the fact that I am pulling
information from multiple databases (Two MSSQL and One Informix)

So if my query just starts out with $sql = "Select * from..." it doesn't
really know which connection to use.


On 6/6/07, Stut <stuttle@gmail.com> wrote:
>
> Dan Shirah wrote:
> > I thought that if you made a connection at the beginning of a page, that
> > you could use that connection throughout the page without having to type
> > it over again as long as you did not explicitly put in code to close the
> > connection?? Which is why I only inserted the include fil at the
> > beginning of the page.
> >
> > Instead of having:
> >
> > $connection = mssql_pconnect('SERVER','user','password') or die ('server
> > connection failed');
> > $database = mssql_select_db("database", $connection) or die ('DB
> > selection failed');
> >
> > in my include file, I should only have $connection instead and then
> > specify $database before the query to the database.
> >
> > Does that sound like the correct solution?

>
> The way you have it at the moment should work fine. Might I suggest you
> try using a non-persistant connection? I've heard things in the past
> that the persistant connection implementation in the MSSQL extension can
> be a bit flakey.
>
> -Stut
>


Reply With Quote
  #26 (permalink)  
Old 06-06-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] More include issues

Use two different $connection variables, say, $mssql and $informix and
pass them in as the optional arg to _query or whatever, and then you
can avoid flip-flopping like that.

On Wed, June 6, 2007 3:53 pm, Dan Shirah wrote:
> It seems that PHP is getting confused unless I post the $database =
> mssql_select_db("database", $connection) or die ('DB selection
> failed');
> before the query. This is probably due to the fact that I am pulling
> information from multiple databases (Two MSSQL and One Informix)
>
> So if my query just starts out with $sql = "Select * from..." it
> doesn't
> really know which connection to use.
>
>
> On 6/6/07, Stut <stuttle@gmail.com> wrote:
>>
>> Dan Shirah wrote:
>> > I thought that if you made a connection at the beginning of a

>> page, that
>> > you could use that connection throughout the page without having

>> to type
>> > it over again as long as you did not explicitly put in code to

>> close the
>> > connection?? Which is why I only inserted the include fil at the
>> > beginning of the page.
>> >
>> > Instead of having:
>> >
>> > $connection = mssql_pconnect('SERVER','user','password') or die

>> ('server
>> > connection failed');
>> > $database = mssql_select_db("database", $connection) or die ('DB
>> > selection failed');
>> >
>> > in my include file, I should only have $connection instead and

>> then
>> > specify $database before the query to the database.
>> >
>> > Does that sound like the correct solution?

>>
>> The way you have it at the moment should work fine. Might I suggest
>> you
>> try using a non-persistant connection? I've heard things in the past
>> that the persistant connection implementation in the MSSQL extension
>> can
>> be a bit flakey.
>>
>> -Stut
>>

>



--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
Reply With Quote
  #27 (permalink)  
Old 06-06-2007
Stut
 
Posts: n/a
Default Re: [PHP] More include issues

Dan Shirah wrote:
> It seems that PHP is getting confused unless I post the $database =
> mssql_select_db("database", $connection) or die ('DB selection failed');
> before the query. This is probably due to the fact that I am pulling
> information from multiple databases (Two MSSQL and One Informix)
>
> So if my query just starts out with $sql = "Select * from..." it doesn't
> really know which connection to use.


OK, that's more than a little annoying. I wish you'd mentioned that
you're using multiple database connection, this would have been so much
easier.

The mssql_query function can take the connection resource as a second
parameter. This also goes for every other database function. If you're
using multiple database connections you *need* to be passing that in. In
fact, even if you're not currently using multiple connections I would
recommend that people always pass the connection resource to the DB
functions - it saves a lot of headaches if you ever need to use a second
connection.

-Stut
Reply With Quote
  #28 (permalink)  
Old 06-06-2007
Dan Shirah
 
Posts: n/a
Default Re: [PHP] More include issues

Sorry Stut, I am fairly newb and don't know all the in's and out's of all
the functionality. I thought I had a good grasp on th edatabase connection
part, but obviously was having a major oversight. Sorry for the confusion
and THANK YOU for sticking with me to get this issue resolved.

I try not to bother the list and figure things out by myself as much as I
can, but it's hard when I was "volunteered" to become the guinea pig to
convert some of our apps from ColdFusion to PHP...especially when nobody I
work with has ever touched PHP before. I have nobody to turn to except
google/forums/this list.

So once again, thank you, and thanks to everyone else that is helping this
novice become more familiar with PHP.


On 6/6/07, Stut <stuttle@gmail.com> wrote:
>
> Dan Shirah wrote:
> > It seems that PHP is getting confused unless I post the $database =
> > mssql_select_db("database", $connection) or die ('DB selection failed');
> > before the query. This is probably due to the fact that I am pulling
> > information from multiple databases (Two MSSQL and One Informix)
> >
> > So if my query just starts out with $sql = "Select * from..." it doesn't
> > really know which connection to use.

>
> OK, that's more than a little annoying. I wish you'd mentioned that
> you're using multiple database connection, this would have been so much
> easier.
>
> The mssql_query function can take the connection resource as a second
> parameter. This also goes for every other database function. If you're
> using multiple database connections you *need* to be passing that in. In
> fact, even if you're not currently using multiple connections I would
> recommend that people always pass the connection resource to the DB
> functions - it saves a lot of headaches if you ever need to use a second
> connection.
>
> -Stut
>


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0