Обсуждение: wouldn't insert
Hi again,
Can someone help me out on this? the function I quoted below is supposed
to restore the values from table temp_contactinfo to contactinfo. But
it's not inserting to the contactinfo table...
There are no errors whatsoever, must be something wrong with the logic
somewhere...
> function restore_contactinfo($connectGovPH, $ctrl_no) {
>
> $query_clear = "delete from contactinfo where ctrl_no = '$ctrl_no'";
> pg_Exec($connectGovPH,$query_clear);
>
> $query = "select * from temp_contactinfo where ctrl_no = '$ctrl_no'";
> $result = pg_Exec($connectGovPH,$query);
> $num = pg_NumRows($result);
>
>
> for($i=0;$i<$num;$i++) {
> $row = pg_Fetch_Object($result,$i);
> $category = $row->category;
> $contact_no = $row->contact_no;
> $contact_name = $row->contact_name;
> $organization_name = $row->organization_name;
> $address = $row->address;
> $telephone = $row->telephone;
> $fax = $row->fax;
> $email = $row->email;
>
> $query2 = "INSERT INTO contactinfo
>
VALUES('$ctrl_no','$category','$contact_no','$contact_name','$organization_name','$address','$telephone','$fax','$email')";
> pg_Exec($connectGovPH,$query2);
>
> $query3 = "DELETE FROM temp_contactinfo WHERE ctrl_no =
> '$ctrl_no' AND category = '$category' AND contact_no = '$contact_no'";
> pg_Exec($connectGovPH,$query3);
> }
> }
I've searched and searched but couldn't find anything wrong with the
code =(
Elijah
Elijah.....
> There are no errors whatsoever, must be something wrong with the logic
> somewhere...
What I do when I can't find errors is break down the code into
smaller steps and add error checking.
Make the connection and check the return value.
Put together the sql statement and print it.
Query the database and check the return value.
and so forth.....
Check php.net to see some examples of error checking.
On another note, if I'm only working with only one db I just connect once
near the start of the script and then use that connection for the
subsequent calls.
brew
==========================================================================
Strange Brew (brew@theMode.com)
Check out my Musician's Online Database Exchange (The MODE Pages)
http://www.TheMode.com
==========================================================================
Hey,
echo out $query2 before it runs, try a few in psql and it should tell
you what the error is....
Chris.
-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org] On Behalf Of Elijah O. Alcantara
Sent: Friday, July 09, 2004 12:39 PM
To: pgsql-php@postgresql.org
Subject: [PHP] wouldn't insert
Hi again,
Can someone help me out on this? the function I quoted below is supposed
to restore the values from table temp_contactinfo to contactinfo. But
it's not inserting to the contactinfo table...
There are no errors whatsoever, must be something wrong with the logic
somewhere...
> function restore_contactinfo($connectGovPH, $ctrl_no) {
>
> $query_clear = "delete from contactinfo where ctrl_no = '$ctrl_no'";
> pg_Exec($connectGovPH,$query_clear);
>
> $query = "select * from temp_contactinfo where ctrl_no = '$ctrl_no'";
> $result = pg_Exec($connectGovPH,$query); $num = pg_NumRows($result);
>
>
> for($i=0;$i<$num;$i++) {
> $row = pg_Fetch_Object($result,$i);
> $category = $row->category;
> $contact_no = $row->contact_no;
> $contact_name = $row->contact_name;
> $organization_name = $row->organization_name;
> $address = $row->address;
> $telephone = $row->telephone;
> $fax = $row->fax;
> $email = $row->email;
>
> $query2 = "INSERT INTO contactinfo
>
VALUES('$ctrl_no','$category','$contact_no','$contact_name','$organizati
on_name','$address','$telephone','$fax','$email')";
> pg_Exec($connectGovPH,$query2);
>
> $query3 = "DELETE FROM temp_contactinfo WHERE ctrl_no =
> '$ctrl_no' AND category = '$category' AND contact_no = '$contact_no'";
> pg_Exec($connectGovPH,$query3);
> }
> }
I've searched and searched but couldn't find anything wrong with the
code =(
Elijah
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if
your
joining column's datatypes do not match
I tried using error_log() but never got any emails...
error_log("This is query2 inserting $ctrl_no $category $contact_no
$organization_name $address $telephone $fax $email", 1,
"elijah@asti.dost.gov.ph");
looks like it never went in the for loop, somethings wrong...
Thanks for the advice,
Elijah
On Sat, 2004-07-10 at 03:08, brew@theMode.com wrote:
> Elijah.....
>
> > There are no errors whatsoever, must be something wrong with the logic
> > somewhere...
>
> What I do when I can't find errors is break down the code into
> smaller steps and add error checking.
>
> Make the connection and check the return value.
>
> Put together the sql statement and print it.
>
> Query the database and check the return value.
>
> and so forth.....
>
> Check php.net to see some examples of error checking.
>
> On another note, if I'm only working with only one db I just connect once
> near the start of the script and then use that connection for the
> subsequent calls.
>
> brew
>
> ==========================================================================
> Strange Brew (brew@theMode.com)
> Check out my Musician's Online Database Exchange (The MODE Pages)
> http://www.TheMode.com
> ==========================================================================
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
error_log won't email you will it? It'll put it into the apache error
log (by default) or the file you specify in your php.ini file, or if you
have it in your script,
ini_set('log_error',......)
And don't separate the query, just error_log it like
error_log($query2);
Chris.
-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org] On Behalf Of Elijah O. Alcantara
Sent: Monday, July 12, 2004 11:46 AM
To: pgsql-php@postgresql.org
Subject: Re: [PHP] wouldn't insert
I tried using error_log() but never got any emails...
error_log("This is query2 inserting $ctrl_no $category $contact_no
$organization_name $address $telephone $fax $email", 1,
"elijah@asti.dost.gov.ph");
looks like it never went in the for loop, somethings wrong...
Thanks for the advice,
Elijah
On Sat, 2004-07-10 at 03:08, brew@theMode.com wrote:
> Elijah.....
>
> > There are no errors whatsoever, must be something wrong with the
> > logic somewhere...
>
> What I do when I can't find errors is break down the code into smaller
> steps and add error checking.
>
> Make the connection and check the return value.
>
> Put together the sql statement and print it.
>
> Query the database and check the return value.
>
> and so forth.....
>
> Check php.net to see some examples of error checking.
>
> On another note, if I'm only working with only one db I just connect
> once near the start of the script and then use that connection for the
> subsequent calls.
>
> brew
>
>
========================================================================
==
> Strange Brew (brew@theMode.com)
> Check out my Musician's Online Database Exchange (The MODE Pages)
> http://www.TheMode.com
> ======================================================================
> ====
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if
your
> joining column's datatypes do not match
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html
I moved the error_log outside the loop and I got log message, now it
looks like the script doesn't pass through the for loop.
I wonder how can it not pass through the for loop ?? it's strange... I
didn't put any 'break' in there for sure ...
Elijah
On Mon, 2004-07-12 at 09:53, Chris wrote:
> error_log won't email you will it? It'll put it into the apache error
> log (by default) or the file you specify in your php.ini file, or if you
> have it in your script,
>
> ini_set('log_error',......)
>
> And don't separate the query, just error_log it like
>
> error_log($query2);
>
> Chris.
>
>
> -----Original Message-----
> From: pgsql-php-owner@postgresql.org
> [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Elijah O. Alcantara
> Sent: Monday, July 12, 2004 11:46 AM
> To: pgsql-php@postgresql.org
> Subject: Re: [PHP] wouldn't insert
>
>
> I tried using error_log() but never got any emails...
>
> error_log("This is query2 inserting $ctrl_no $category $contact_no
> $organization_name $address $telephone $fax $email", 1,
> "elijah@asti.dost.gov.ph");
>
> looks like it never went in the for loop, somethings wrong...
>
> Thanks for the advice,
> Elijah
>
> On Sat, 2004-07-10 at 03:08, brew@theMode.com wrote:
> > Elijah.....
> >
> > > There are no errors whatsoever, must be something wrong with the
> > > logic somewhere...
> >
> > What I do when I can't find errors is break down the code into smaller
>
> > steps and add error checking.
> >
> > Make the connection and check the return value.
> >
> > Put together the sql statement and print it.
> >
> > Query the database and check the return value.
> >
> > and so forth.....
> >
> > Check php.net to see some examples of error checking.
> >
> > On another note, if I'm only working with only one db I just connect
> > once near the start of the script and then use that connection for the
>
> > subsequent calls.
> >
> > brew
> >
> >
> ========================================================================
> ==
> > Strange Brew (brew@theMode.com)
> > Check out my Musician's Online Database Exchange (The MODE Pages)
> > http://www.TheMode.com
> > ======================================================================
> > ====
> >
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 9: the planner will ignore your desire to choose an index scan if
> your
> > joining column's datatypes do not match
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>
Bingo! no wonder it can't push through the loop, there wasn't any
results in the first place at the first query. Error_log()'s very useful
=)
Thanks,
Elijah
On Mon, 2004-07-12 at 09:45, Elijah O. Alcantara wrote:
> I tried using error_log() but never got any emails...
>
> error_log("This is query2 inserting $ctrl_no $category $contact_no
> $organization_name $address $telephone $fax $email", 1,
> "elijah@asti.dost.gov.ph");
>
> looks like it never went in the for loop, somethings wrong...
>
> Thanks for the advice,
> Elijah
>
> On Sat, 2004-07-10 at 03:08, brew@theMode.com wrote:
> > Elijah.....
> >
> > > There are no errors whatsoever, must be something wrong with the logic
> > > somewhere...
> >
> > What I do when I can't find errors is break down the code into
> > smaller steps and add error checking.
> >
> > Make the connection and check the return value.
> >
> > Put together the sql statement and print it.
> >
> > Query the database and check the return value.
> >
> > and so forth.....
> >
> > Check php.net to see some examples of error checking.
> >
> > On another note, if I'm only working with only one db I just connect once
> > near the start of the script and then use that connection for the
> > subsequent calls.
> >
> > brew
> >
> > ==========================================================================
> > Strange Brew (brew@theMode.com)
> > Check out my Musician's Online Database Exchange (The MODE Pages)
> > http://www.TheMode.com
> > ==========================================================================
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 9: the planner will ignore your desire to choose an index scan if your
> > joining column's datatypes do not match
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
This subject came up tangentially in the -hackers list. You should look at using the following functions: http://www.php.net/manual/en/function.pg-result-error.php http://www.php.net/manual/en/function.pg-result-status.php supported since 4.2.0 came out a little over two years ago. Very nice way to catch and handle errors. On Sun, 2004-07-11 at 19:45, Elijah O. Alcantara wrote: > I tried using error_log() but never got any emails... > > error_log("This is query2 inserting $ctrl_no $category $contact_no > $organization_name $address $telephone $fax $email", 1, > "elijah@asti.dost.gov.ph"); > > looks like it never went in the for loop, somethings wrong... > > Thanks for the advice, > Elijah > > On Sat, 2004-07-10 at 03:08, brew@theMode.com wrote: > > Elijah..... > > > > > There are no errors whatsoever, must be something wrong with the logic > > > somewhere... > > > > What I do when I can't find errors is break down the code into > > smaller steps and add error checking. > > > > Make the connection and check the return value. > > > > Put together the sql statement and print it. > > > > Query the database and check the return value. > > > > and so forth..... > > > > Check php.net to see some examples of error checking. > > > > On another note, if I'm only working with only one db I just connect once > > near the start of the script and then use that connection for the > > subsequent calls. > > > > brew > > > > ========================================================================== > > Strange Brew (brew@theMode.com) > > Check out my Musician's Online Database Exchange (The MODE Pages) > > http://www.TheMode.com > > ========================================================================== > > > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 9: the planner will ignore your desire to choose an index scan if your > > joining column's datatypes do not match > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html >
Mind if I ask another question? I've been logging errors lately and found a 'Resource id #12' in one of the query results, what does this mean? Elijah
On Mon, 2004-07-12 at 13:20 +0800, Elijah O. Alcantara wrote:
> Mind if I ask another question? I've been logging errors lately and
> found a 'Resource id #12' in one of the query results, what does this
> mean?
That's what you get when you try and print something that shouldn't
really be printed. Generally complex objects where there is little
value implementing some more complex behaviour when passed to the print
routines.
Knowing the id# is about as useful as it can get, for when you need to
see if it's the same resource as a different whatever-it-is.
Cheers,
Andrew.
-------------------------------------------------------------------------
Andrew @ Catalyst .Net .NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)803-2201 MOB: +64(272)DEBIAN OFFICE: +64(4)499-2267
Make things as simple as possible, but no simpler -- Einstein
-------------------------------------------------------------------------
Вложения
Something that shouldn't be printed ... hmmm.. does the postgresql site have a list of these Resource id's? I've been looking all over google for this and found nothing. =( Elijah On Mon, 2004-07-12 at 15:38, Andrew McMillan wrote: > On Mon, 2004-07-12 at 13:20 +0800, Elijah O. Alcantara wrote: > > Mind if I ask another question? I've been logging errors lately and > > found a 'Resource id #12' in one of the query results, what does this > > mean? > > That's what you get when you try and print something that shouldn't > really be printed. Generally complex objects where there is little > value implementing some more complex behaviour when passed to the print > routines. > > Knowing the id# is about as useful as it can get, for when you need to > see if it's the same resource as a different whatever-it-is. > > Cheers, > Andrew. > > ------------------------------------------------------------------------- > Andrew @ Catalyst .Net .NZ Ltd, PO Box 11-053, Manners St, Wellington > WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St > DDI: +64(4)803-2201 MOB: +64(272)DEBIAN OFFICE: +64(4)499-2267 > Make things as simple as possible, but no simpler -- Einstein > -------------------------------------------------------------------------
> Something that shouldn't be printed ... hmmm.. does the postgresql site > have a list of these Resource id's? I've been looking all over google > for this and found nothing. =( That's because it's nothing to do with Postgres. Try reading the PHP docs. Chris
On Sun, 2004-07-11 at 23:20, Elijah O. Alcantara wrote:
> Mind if I ask another question? I've been logging errors lately and
> found a 'Resource id #12' in one of the query results, what does this
> mean?
A "Resource id #12" is a handle to a resource in PHP. It comes from
something like this:
$conn = pg_connect("...
$query = "select * from sometable";
$res = pg_query ($conn,$query);
$res will now have something like "Resource id #12" in it. I.e. it's
not some constant that means anything, it's a handle to the result set
php now has in memory and what you use to access it via the
pg_fetch_array functions et. al.
on 7/12/04 4:01 AM, Elijah O. Alcantara at elijah@asti.dost.gov.ph wrote: > Something that shouldn't be printed ... hmmm.. does the postgresql site > have a list of these Resource id's? I've been looking all over google > for this and found nothing. =( The number doesn't mean anything - it just labels a specific resource that's stored in a variable, which could be a database connection or a result set or any of several other things. I've found that the most common reason for running into a resource ID reference is that I've tried to treat a result set as if it were an array in my code, without having done a pg_fetch_row() or pg_fetch_all() or whatever on it first. I'd suggest seeing what variable contains the resource, and then looking back in your code to see when that variable was defined and what it might contain. If it is a result set, use one of the above functions to turn it into an array before trying to print it. Of course, there are other tricks to printing an array, but that depends on what you're trying to do with it. If you just want to see what's in it, the simplest way is to use print_r(). Lynna -- Resource Centre Database Coordinator Gallery 44: www.gallery44.org Database Project: www.gallery44db.org