CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Second DB Connection Crashes Function

Print topic Send  topic

Author Message
DonP
Posted: 02/26/2008, 1:51 PM

I have a function that creates the form fields for a shopping cart and I
have moved the shipping information to its own database where all my
sites can share it and to make maintenance easier. The CCS 3.2 project
has the second connection established and I can open it in the function
but as soon as I run a query, it loses all values that were set in the
"main" query. There are no shared variable names between them so I am at
a loss! Is there something in CCS or even in PHP to prevent two
different databases being queried within the same function? If so, is
there a workaround?

Thanks.

Don (DonP)
datadoit
Posted: 02/26/2008, 2:09 PM

Can you post your code? I assume it's custom code in an
AfterUpdate/Insert type of event.
DonP
Posted: 02/26/2008, 2:34 PM

The code is being called in a Before Show event since its purpose is to
supply form tags. The whole thing is probably too long to post but this
is the part with the second connection that is causing the problems (if
you want the whole thing, let me know):

// Item Form Shipping
$DBgeoip = new clsDBgeoip();

if (CCGetSession("CountryID") != 1) {

if (!$ShippingWeight) {
$ShippingWeight = "6";
}

$SQLRateGroup = "SELECT FirstClass ".
"FROM country_listing cl ".
"LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
"WHERE ID = ".CCGetSession("CountryID");

$DBgeoip->query($SQLRateGroup);
$ResultRateGroup = $DBgeoip->next_record();

if ($ResultRateGroup) {
$CountryZone = $DBgeoip->f("FirstClass");
}

$DBgeoip->close();

$GroupItem = "Group". $CountryZone;

if ($GroupItem) {
$ShippingRate = CCDLookUp($GroupItem, "shipping_rates", "Weight >= '".
$ShippingWeight ."' LIMIT 1", $DBgeoip);

$ShippingValue = number_format($ShippingRate, 2, ".", "");
$output[] = '<input type="hidden" name="shipping"
value="'.$ShippingValue.'">';
$output[] = '<input type="hidden" name="shipping_extra" value="1">';
$output[] = '<input type="hidden" name="shipping2" value="1.00">';
}

} else {
$output[] = '<input type="hidden" name="shipping_extra" value="0">';
}

The $DBgeoip->query($SQLRateGroup); and anything after is what seems to
be crashing it.

Don (DonP)

DonP wrote:
> I have a function that creates the form fields for a shopping cart and I
> have moved the shipping information to its own database where all my
> sites can share it and to make maintenance easier. The CCS 3.2 project
> has the second connection established and I can open it in the function
> but as soon as I run a query, it loses all values that were set in the
> "main" query. There are no shared variable names between them so I am at
> a loss! Is there something in CCS or even in PHP to prevent two
> different databases being queried within the same function? If so, is
> there a workaround?
>
> Thanks.
>
> Don (DonP)
datadoit
Posted: 02/26/2008, 2:50 PM

For this part:

$DBgeoip = new clsDBgeoip();

is the $DBgeoip connection class already used on the page elsewhere? If
not, I believe you're going to have to globalize it.

global $DBgeoip;
$DBgeoip = new clsDBgeoip();

Secondly, I noticed that while you're in a connection's record
($DBgeoip->next_record()), you're using the same connection again in a
CCDLookUp() function. I'd change that to use a new connection also.

$db = new clsDBgeoip();
CCDLookUp(..., $db);

Don't know if these will solve your problem, just some obvious things
noticed.
DonP
Posted: 02/26/2008, 4:23 PM

Thanks as sometimes the obvious things are the most difficult to spot!

If I remark out everything after $DBgeoip->query($SQLRateGroup); it
still crashes but if I also remark out this line it does not so it is
something to do with the second connection itself that is messing up the
first one. The errors, though, are all on the first connection where all
the variables suddenly don't exist anymore.

This second connection does not already exist on the page but I didn't
think it needed to as long as it was available for the project. Even so,
I wasn't aware that I needed to globalize a variable that was being
specifically declared but I tried it and it made no difference.

I also tried putting this code into its own function and then calling it
from the other function but it still crashes with the same errors. I
just don't see what even the grossest of coding errors would have to do
with the other connection!

Don (DonP)

datadoit wrote:
> For this part:
>
> $DBgeoip = new clsDBgeoip();
>
> is the $DBgeoip connection class already used on the page elsewhere? If
> not, I believe you're going to have to globalize it.
>
> global $DBgeoip;
> $DBgeoip = new clsDBgeoip();
>
> Secondly, I noticed that while you're in a connection's record
> ($DBgeoip->next_record()), you're using the same connection again in a
> CCDLookUp() function. I'd change that to use a new connection also.
>
> $db = new clsDBgeoip();
> CCDLookUp(..., $db);
>
> Don't know if these will solve your problem, just some obvious things
> noticed.
wkempees
Posted: 02/26/2008, 4:55 PM

My 2ct:

You are defining a new connection $DBGeoip with the same name as the
original?
I would do something like $db2 = new clsDBgeoip();
that would avoid messing up data obtained from a global defined connection
with the same name.
I miss the $db2->open().
Is the result from db2->query($SQLRateGroup) always 1 record, or do you just
want the first?
Normaly I would expect a while loop...
More important..... you do a $DBgeoip->close(), after which you do
CCDLookup().
I would change $DBgeoip->close(), as I stated earlier into $DB2->close()
and have a global $DBgeoip; at the entry of the routine to cater for the
CCDlookup.

Hope this makes sense....
Walter


"DonP" <forum@pc-homepage.com> schreef in bericht
news:fq244u$r4d$1@news.codecharge.com...
> The code is being called in a Before Show event since its purpose is to
> supply form tags. The whole thing is probably too long to post but this is
> the part with the second connection that is causing the problems (if you
> want the whole thing, let me know):
>
> // Item Form Shipping
> $DBgeoip = new clsDBgeoip();
>
> if (CCGetSession("CountryID") != 1) {
>
> if (!$ShippingWeight) {
> $ShippingWeight = "6";
> }
>
> $SQLRateGroup = "SELECT FirstClass ".
> "FROM country_listing cl ".
> "LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
> "WHERE ID = ".CCGetSession("CountryID");
>
> $DBgeoip->query($SQLRateGroup);
> $ResultRateGroup = $DBgeoip->next_record();
>
> if ($ResultRateGroup) {
> $CountryZone = $DBgeoip->f("FirstClass");
> }
>
> $DBgeoip->close();
>
> $GroupItem = "Group". $CountryZone;
>
> if ($GroupItem) {
> $ShippingRate = CCDLookUp($GroupItem, "shipping_rates", "Weight >= '".
> $ShippingWeight ."' LIMIT 1", $DBgeoip);
>
> $ShippingValue = number_format($ShippingRate, 2, ".", "");
> $output[] = '<input type="hidden" name="shipping"
> value="'.$ShippingValue.'">';
> $output[] = '<input type="hidden" name="shipping_extra" value="1">';
> $output[] = '<input type="hidden" name="shipping2" value="1.00">';
> }
>
> } else {
> $output[] = '<input type="hidden" name="shipping_extra" value="0">';
> }
>
> The $DBgeoip->query($SQLRateGroup); and anything after is what seems to be
> crashing it.
>
> Don (DonP)
>
> DonP wrote:
>> I have a function that creates the form fields for a shopping cart and I
>> have moved the shipping information to its own database where all my
>> sites can share it and to make maintenance easier. The CCS 3.2 project
>> has the second connection established and I can open it in the function
>> but as soon as I run a query, it loses all values that were set in the
>> "main" query. There are no shared variable names between them so I am at
>> a loss! Is there something in CCS or even in PHP to prevent two different
>> databases being queried within the same function? If so, is there a
>> workaround?
>>
>> Thanks.
>>
>> Don (DonP)

wkempees
Posted: 02/26/2008, 5:00 PM

afterthought
It is the $DBgeoip->close() that messes everything up.
Confirm?

Walter

DonP
Posted: 02/26/2008, 5:59 PM

I am beginning to think that there is something very basically wrong
with the second connection even though by itself it runs just fine. As a
test, I remarked out the entire first function and ran only the second
one by itself and it does indeed work. It's only both together that have
issues!

To answer your questions, no, the connections names are not the same at
all between the main connection and this second one. I have also further
isolated them into two separate functions but as soon as I call the
second function from the first, it gives errors just as it did when the
two were in a single function.

Yes, the result of the CCDLookUp is just one record. However, the crash
isn't anything to do with the CCDLookUp because it has the same problems
even when it is remarked out.

As for expecting a loop, the grid itself does the looping and with each
record it passes an ID value to the first function, queries the database
to get the additional details including $ShippingWeight, then the second
function is supposed to process the weight and provide the hidden form
tags with the value.

Don (DonP)

wkempees wrote:
> My 2ct:
>
> You are defining a new connection $DBGeoip with the same name as the
> original?
> I would do something like $db2 = new clsDBgeoip();
> that would avoid messing up data obtained from a global defined connection
> with the same name.
> I miss the $db2->open().
> Is the result from db2->query($SQLRateGroup) always 1 record, or do you just
> want the first?
> Normaly I would expect a while loop...
> More important..... you do a $DBgeoip->close(), after which you do
> CCDLookup().
> I would change $DBgeoip->close(), as I stated earlier into $DB2->close()
> and have a global $DBgeoip; at the entry of the routine to cater for the
> CCDlookup.
>
> Hope this makes sense....
> Walter
>
>
> "DonP" <forum@pc-homepage.com> schreef in bericht
>news:fq244u$r4d$1@news.codecharge.com...
>> The code is being called in a Before Show event since its purpose is to
>> supply form tags. The whole thing is probably too long to post but this is
>> the part with the second connection that is causing the problems (if you
>> want the whole thing, let me know):
>>
>> // Item Form Shipping
>> $DBgeoip = new clsDBgeoip();
>>
>> if (CCGetSession("CountryID") != 1) {
>>
>> if (!$ShippingWeight) {
>> $ShippingWeight = "6";
>> }
>>
>> $SQLRateGroup = "SELECT FirstClass ".
>> "FROM country_listing cl ".
>> "LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
>> "WHERE ID = ".CCGetSession("CountryID");
>>
>> $DBgeoip->query($SQLRateGroup);
>> $ResultRateGroup = $DBgeoip->next_record();
>>
>> if ($ResultRateGroup) {
>> $CountryZone = $DBgeoip->f("FirstClass");
>> }
>>
>> $DBgeoip->close();
>>
>> $GroupItem = "Group". $CountryZone;
>>
>> if ($GroupItem) {
>> $ShippingRate = CCDLookUp($GroupItem, "shipping_rates", "Weight >= '".
>> $ShippingWeight ."' LIMIT 1", $DBgeoip);
>>
>> $ShippingValue = number_format($ShippingRate, 2, ".", "");
>> $output[] = '<input type="hidden" name="shipping"
>> value="'.$ShippingValue.'">';
>> $output[] = '<input type="hidden" name="shipping_extra" value="1">';
>> $output[] = '<input type="hidden" name="shipping2" value="1.00">';
>> }
>>
>> } else {
>> $output[] = '<input type="hidden" name="shipping_extra" value="0">';
>> }
>>
>> The $DBgeoip->query($SQLRateGroup); and anything after is what seems to be
>> crashing it.
>>
>> Don (DonP)
>>
>> DonP wrote:
>>> I have a function that creates the form fields for a shopping cart and I
>>> have moved the shipping information to its own database where all my
>>> sites can share it and to make maintenance easier. The CCS 3.2 project
>>> has the second connection established and I can open it in the function
>>> but as soon as I run a query, it loses all values that were set in the
>>> "main" query. There are no shared variable names between them so I am at
>>> a loss! Is there something in CCS or even in PHP to prevent two different
>>> databases being queried within the same function? If so, is there a
>>> workaround?
>>>
>>> Thanks.
>>>
>>> Don (DonP)
>
>
DonP
Posted: 02/26/2008, 6:02 PM

No, it messes up whether or not $DBgeoip->close() is there. It messes up
on $DBgeoip->query($SQLRateGroup); In fact, it messes up even if
everything after this line is remarked out.

Don (DonP)

wkempees wrote:
> afterthought
> It is the $DBgeoip->close() that messes everything up.
> Confirm?
>
> Walter
>
>
DonP
Posted: 02/26/2008, 6:11 PM

You are right that the $DBgeoip->close() was in the wrong place but it
isn't the problem. Thanks for pointing it out, though.

Don (DonP)

wkempees wrote:
> afterthought
> It is the $DBgeoip->close() that messes everything up.
> Confirm?
>
> Walter
>
>
wkempees


Posts: 1679
Posted: 02/26/2008, 6:45 PM

- Where is the $DBgeoip->open()?
-$SQLRateGroup = "SELECT FirstClass ".
>> "FROM country_listing cl ".
>> "LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
>> "WHERE ID = ".CCGetSession("CountryID");
Table country_listing, does it have a field ID?
Table countries, does it have a field ID?
As you keep saying the $SQLRatGroup is the culprit, it either
returns more than one row or has ambigeous fieldnames or the DB was not open()ed.

One of these.....?



_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
DonP
Posted: 02/26/2008, 7:16 PM

That's a good question. countries has an ID but country_listing, which
was created from a USPS chart, does not. The query itself runs just fine
when run in a MySQL management application (HeidiSQL) Except for
CountryName, the two do not have any field names in common. As an
experiment, I ran a very basic non-joined query and it gave the same error.

If I run this function by itself, the query runs without errors. Somehow
the two together are the issue.

Don (DonP)

wkempees wrote:
> - Where is the $DBgeoip->open()?
> -$SQLRateGroup = "SELECT FirstClass ".
>>> "FROM country_listing cl ".
>>> "LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
>>> "WHERE ID = ".CCGetSession("CountryID");
> Table country_listing, does it have a field ID?
> Table countries, does it have a field ID?
> As you keep saying the $SQLRatGroup is the culprit, it either
> returns more than one row or has ambiguous fieldnames or the DB was not
> open()ed.
>
> One of these.....?
>
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
DonB
Posted: 02/26/2008, 8:04 PM

This is actually two different database servers or two connections to one
server?. Is it MySQL 5.0.19, which has some known bugginess?

--
DonB



"DonP" <forum@pc-homepage.com> wrote in message
news:fq2kn4$63f$1@news.codecharge.com...
> That's a good question. countries has an ID but country_listing, which was
> created from a USPS chart, does not. The query itself runs just fine when
> run in a MySQL management application (HeidiSQL) Except for CountryName,
> the two do not have any field names in common. As an experiment, I ran a
> very basic non-joined query and it gave the same error.
>
> If I run this function by itself, the query runs without errors. Somehow
> the two together are the issue.
>
> Don (DonP)
>
> wkempees wrote:
>> - Where is the $DBgeoip->open()?
>> -$SQLRateGroup = "SELECT FirstClass ".
>>>> "FROM country_listing cl ".
>>>> "LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
>>>> "WHERE ID = ".CCGetSession("CountryID");
>> Table country_listing, does it have a field ID?
>> Table countries, does it have a field ID?
>> As you keep saying the $SQLRatGroup is the culprit, it either
>> returns more than one row or has ambiguous fieldnames or the DB was not
>> open()ed.
>>
>> One of these.....?
>>
>>
>>
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>

DonB
Posted: 02/26/2008, 8:04 PM

Oh, and what about the client library versions - different versions between
servers (assuming the answer to that question was 'yes'). Do they have
different default character set encodings?

My suspicion lies with different DB libraries loading and conflicting.
Duplicating the necessary tables on the same database temporarily so the two
connections go to the same server, to see if the problem continues or goes
away, might be interesting to try. At least you could rule in/out CCS having
a problem.

--
DonB



"DonP" <forum@pc-homepage.com> wrote in message
news:fq2kn4$63f$1@news.codecharge.com...
> That's a good question. countries has an ID but country_listing, which was
> created from a USPS chart, does not. The query itself runs just fine when
> run in a MySQL management application (HeidiSQL) Except for CountryName,
> the two do not have any field names in common. As an experiment, I ran a
> very basic non-joined query and it gave the same error.
>
> If I run this function by itself, the query runs without errors. Somehow
> the two together are the issue.
>
> Don (DonP)
>
> wkempees wrote:
>> - Where is the $DBgeoip->open()?
>> -$SQLRateGroup = "SELECT FirstClass ".
>>>> "FROM country_listing cl ".
>>>> "LEFT JOIN countries c ON cl.CountryName = c.CountryName ".
>>>> "WHERE ID = ".CCGetSession("CountryID");
>> Table country_listing, does it have a field ID?
>> Table countries, does it have a field ID?
>> As you keep saying the $SQLRatGroup is the culprit, it either
>> returns more than one row or has ambiguous fieldnames or the DB was not
>> open()ed.
>>
>> One of these.....?
>>
>>
>>
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>

DonP
Posted: 02/26/2008, 8:33 PM

It is one physical server with two connections, tested only on my
development PC so far. MySQL is version 4.1.18 so as to be close to the
version used by my hosting company.

Don (DonP)

DonB wrote:
> This is actually two different database servers or two connections to one
> server?. Is it MySQL 5.0.19, which has some known bugginess?
>

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.