Обсуждение: PHP Related Problem

Поиск
Список
Период
Сортировка

PHP Related Problem

От
John Clark Naldoza y Lopez
Дата:
Hi,


I've got a table with the following structure:

CREATE TABLE assignment_answers
(
    training_id INT4,
    lesson_no INT2,
    assignment_no INT2,
    FOREIGN KEY( training_id, lesson_no, assignment_no ) REFERENCES
assignment ON UPDATE CASCADE ON DELETE CASCADE,
    participants_id INT4,
    FOREIGN KEY( training_id, participants_id ) REFERENCES
training_participants ON UPDATE CASCADE ON DELETE CASCADE,
    answer TEXT,
    isHTML boolean DEFAULT 'false',
    submitted TIMESTAMP DEFAULT now()
);

And I have a certain function which executes the following SQL_QUERY
under PHP:

SELECT * FROM assignment_answers;

After execution I check my Result resource which has the following value

RESULT_SET == []

Warning: Supplied argument is not a valid PostgreSQL result resource,

When I use psql to access the data this is what I get:

train=> SELECT * FROM assignment_answers ;
 training_id | lesson_no | assignment_no | participants_id | answer |
ishtml |       submitted
-------------+-----------+---------------+-----------------+--------+--------+------------------------
           1 |         1 |             1 |               1 | aaa    |
f      | 2001-09-26 20:10:59+08
           1 |         1 |             2 |               1 | sddd   |
t      | 2001-09-26 20:10:59+08
           1 |         1 |             3 |               1 | bbb    |
f      | 2001-09-26 20:10:59+08
(3 rows)

How can this be?

When all my other statements work find...  Even INSERTing and UPDATEing
to this table works...  I just can't access it's data... =(

I've got PHP 4.0.4 and PostgreSQL 7.0.3 installed in my test system.

Hope someone can shed some light over here...  even RTFM would be great,
if you can point me to where it is in the FM =)

Cheers,


John Clark

--
     /) John Clark Naldoza y Lopez                           (\
    / )    Software Design Engineer III                      ( \
  _( (_    _  Web-Application Development                    _) )_
 (((\ \>  /_>    Cable Modem Network Management System <_\  </ /)))
 (\\\\ \_/ /         NEC Telecom Software Phils., Inc.  \ \_/ ////)
  \       /                                              \       /
   \    _/  phone: (+63 32) 233-9142 loc. 3113            \_    /
   /   /  cellphone: (+63 919) 399-4742                     \   \
  /   / email: njclark@ntsp.nec.co.jp                        \   \


"Intelligence is the ability to avoid doing work, yet getting the work
done"
--Linus Torvalds

Re: PHP Related Problem

От
"Mitch Vincent"
Дата:
Can you show the PHP you're using to connect to and query the database?

Just an FYI but there is a pgsql-php list too :-)


-Mitch

----- Original Message -----
From: "John Clark Naldoza y Lopez" <njclark@ntsp.nec.co.jp>
To: <pgsql-general@postgresql.org>
Sent: Wednesday, September 26, 2001 8:24 AM
Subject: [GENERAL] PHP Related Problem


> Hi,
>
>
> I've got a table with the following structure:
>
> CREATE TABLE assignment_answers
> (
>     training_id INT4,
>     lesson_no INT2,
>     assignment_no INT2,
>     FOREIGN KEY( training_id, lesson_no, assignment_no ) REFERENCES
> assignment ON UPDATE CASCADE ON DELETE CASCADE,
>     participants_id INT4,
>     FOREIGN KEY( training_id, participants_id ) REFERENCES
> training_participants ON UPDATE CASCADE ON DELETE CASCADE,
>     answer TEXT,
>     isHTML boolean DEFAULT 'false',
>     submitted TIMESTAMP DEFAULT now()
> );
>
> And I have a certain function which executes the following SQL_QUERY
> under PHP:
>
> SELECT * FROM assignment_answers;
>
> After execution I check my Result resource which has the following value
>
> RESULT_SET == []
>
> Warning: Supplied argument is not a valid PostgreSQL result resource,
>
> When I use psql to access the data this is what I get:
>
> train=> SELECT * FROM assignment_answers ;
>  training_id | lesson_no | assignment_no | participants_id | answer |
> ishtml |       submitted
> -------------+-----------+---------------+-----------------+--------+-----
---+------------------------
>            1 |         1 |             1 |               1 | aaa    |
> f      | 2001-09-26 20:10:59+08
>            1 |         1 |             2 |               1 | sddd   |
> t      | 2001-09-26 20:10:59+08
>            1 |         1 |             3 |               1 | bbb    |
> f      | 2001-09-26 20:10:59+08
> (3 rows)
>
> How can this be?
>
> When all my other statements work find...  Even INSERTing and UPDATEing
> to this table works...  I just can't access it's data... =(
>
> I've got PHP 4.0.4 and PostgreSQL 7.0.3 installed in my test system.
>
> Hope someone can shed some light over here...  even RTFM would be great,
> if you can point me to where it is in the FM =)
>
> Cheers,
>
>
> John Clark
>
> --
>      /) John Clark Naldoza y Lopez                           (\
>     / )    Software Design Engineer III                      ( \
>   _( (_    _  Web-Application Development                    _) )_
>  (((\ \>  /_>    Cable Modem Network Management System <_\  </ /)))
>  (\\\\ \_/ /         NEC Telecom Software Phils., Inc.  \ \_/ ////)
>   \       /                                              \       /
>    \    _/  phone: (+63 32) 233-9142 loc. 3113            \_    /
>    /   /  cellphone: (+63 919) 399-4742                     \   \
>   /   / email: njclark@ntsp.nec.co.jp                        \   \
>
>
> "Intelligence is the ability to avoid doing work, yet getting the work
> done"
> --Linus Torvalds
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>


Re: PHP Related Problem

От
"Brent R. Matzelle"
Дата:
--- John Clark Naldoza y Lopez <njclark@ntsp.nec.co.jp> wrote:
> When all my other statements work find...  Even INSERTing and
> UPDATEing
> to this table works...  I just can't access it's data... =(

Are you saying that you can run INSERT statements in PHP but no
SELECT statements?  I'll need to see your PHP code in order to
troubleshoot further.

Brent

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger. http://im.yahoo.com

Re: PHP Related Problem

От
Keary Suska
Дата:
As has been said, this is an issue with your PHP code, and can't be
determined without seeing it.

Hint: You cannot use a database handle as a global variable outside of its
native scope in certain versions of PHP. 4.0.6 corrects this problem.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"

> From: John Clark Naldoza y Lopez <njclark@ntsp.nec.co.jp>
> Organization: NEC Telecom Software
> Date: Wed, 26 Sep 2001 20:24:15 +0800
> To: "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
> Subject: [GENERAL] PHP Related Problem
>
> Hi,
>
>
> I've got a table with the following structure:
>
> CREATE TABLE assignment_answers
> (
> training_id INT4,
> lesson_no INT2,
> assignment_no INT2,
> FOREIGN KEY( training_id, lesson_no, assignment_no ) REFERENCES
> assignment ON UPDATE CASCADE ON DELETE CASCADE,
> participants_id INT4,
> FOREIGN KEY( training_id, participants_id ) REFERENCES
> training_participants ON UPDATE CASCADE ON DELETE CASCADE,
> answer TEXT,
> isHTML boolean DEFAULT 'false',
> submitted TIMESTAMP DEFAULT now()
> );
>
> And I have a certain function which executes the following SQL_QUERY
> under PHP:
>
> SELECT * FROM assignment_answers;
>
> After execution I check my Result resource which has the following value
>
> RESULT_SET == []
>
> Warning: Supplied argument is not a valid PostgreSQL result resource,
>
> When I use psql to access the data this is what I get:
>
> train=> SELECT * FROM assignment_answers ;
> training_id | lesson_no | assignment_no | participants_id | answer |
> ishtml |       submitted
> -------------+-----------+---------------+-----------------+--------+--------+
> ------------------------
> 1 |         1 |             1 |               1 | aaa    |
> f      | 2001-09-26 20:10:59+08
> 1 |         1 |             2 |               1 | sddd   |
> t      | 2001-09-26 20:10:59+08
> 1 |         1 |             3 |               1 | bbb    |
> f      | 2001-09-26 20:10:59+08
> (3 rows)
>
> How can this be?
>
> When all my other statements work find...  Even INSERTing and UPDATEing
> to this table works...  I just can't access it's data... =(
>
> I've got PHP 4.0.4 and PostgreSQL 7.0.3 installed in my test system.
>
> Hope someone can shed some light over here...  even RTFM would be great,
> if you can point me to where it is in the FM =)
>
> Cheers,
>
>
> John Clark
>
> --
> /) John Clark Naldoza y Lopez                           (¥
> / )    Software Design Engineer III                      ( ¥
> _( (_    _  Web-Application Development                    _) )_
> (((¥ ¥>  /_>    Cable Modem Network Management System <_¥  </ /)))
> (¥¥¥¥ ¥_/ /         NEC Telecom Software Phils., Inc.  ¥ ¥_/ ////)
> ¥       /                                              ¥       /
> ¥    _/  phone: (+63 32) 233-9142 loc. 3113            ¥_    /
> /   /  cellphone: (+63 919) 399-4742                     ¥   ¥
> /   / email: njclark@ntsp.nec.co.jp                        ¥   ¥
>
>
> "Intelligence is the ability to avoid doing work, yet getting the work
> done"
> --Linus Torvalds
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>


Re: PHP Related Problem

От
John Clark Naldoza y Lopez
Дата:
Keary Suska wrote:
>
> As has been said, this is an issue with your PHP code, and can't be
> determined without seeing it.

I think I just needed a break =)

Here's the problem =)

$select_query = "SELECT assignment_no, answer, isHTML FROM
assignment_answers WHERE training_id=$TRAINING_ID AND
lesson_no=$LESSON_NO AND participants_id=$PARTICIPANTS_ID ORDER BY
assignment_no;";
$res = sql_query($select_sql);

I should've been using

$select_query =) in my call to the sql_query() function =)

>
> Hint: You cannot use a database handle as a global variable outside of its
> native scope in certain versions of PHP. 4.0.6 corrects this problem.
>

Yes, you can...  I'm using the pgsql.inc from the MRBS
(http://mrbs.sourceforge.net) guys, and I am using 4.0.4pl1 =)

Thanks.


Cheers,


John Clark
--
     /) John Clark Naldoza y Lopez                           (\
    / )    Software Design Engineer III                      ( \
  _( (_    _  Web-Application Development                    _) )_
 (((\ \>  /_>    Cable Modem Network Management System <_\  </ /)))
 (\\\\ \_/ /         NEC Telecom Software Phils., Inc.  \ \_/ ////)
  \       /                                              \       /
   \    _/  phone: (+63 32) 233-9142 loc. 3113            \_    /
   /   /  cellphone: (+63 919) 399-4742                     \   \
  /   / email: njclark@ntsp.nec.co.jp                        \   \


"Intelligence is the ability to avoid doing work, yet getting the work
done"
--Linus Torvalds

Re: PHP Related Problem

От
"Nikola Milutinovic"
Дата:
> I've got a table with the following structure:
>
> CREATE TABLE assignment_answers
> (
>     training_id INT4,
>     lesson_no INT2,
>     assignment_no INT2,
>     FOREIGN KEY( training_id, lesson_no, assignment_no ) REFERENCES
> assignment ON UPDATE CASCADE ON DELETE CASCADE,
>     participants_id INT4,
>     FOREIGN KEY( training_id, participants_id ) REFERENCES
> training_participants ON UPDATE CASCADE ON DELETE CASCADE,
>     answer TEXT,
>     isHTML boolean DEFAULT 'false',
>     submitted TIMESTAMP DEFAULT now()
> );
>
> And I have a certain function which executes the following SQL_QUERY
> under PHP:
>
> SELECT * FROM assignment_answers;
>
> After execution I check my Result resource which has the following value
>
> RESULT_SET == []
>
> Warning: Supplied argument is not a valid PostgreSQL result resource,

res = pg_Exec( conn, "SELECT * FROM assignment_answers" );
if( pg_numrows( res ) != 0 ) {
  for( i=0 ; i<pg_numrows( res ) ; ++i ) {
    row = pg_fecharray( res, i );
    /* do your stuff here */
  }
} else {
  /* report error or whatever */
}

Nix.

Re: PHP Related Problem

От
John Clark Naldoza y Lopez
Дата:
Hi,


Thanks, on a previous post I've already stated that I found the
culprit..  I think I got cross-eyed or something =)

>
> res = pg_Exec( conn, "SELECT * FROM assignment_answers" );

$res = pg_Exec( $conn, "SELECT * FROM assignment_answers" );

> if( pg_numrows( res ) != 0 ) {

if( pg_numrows( $res ) != 0 ) {

>   for( i=0 ; i<pg_numrows( res ) ; ++i ) {

for( $i=0 ; $i<pg_numrows( $res ) ; ++$i ) {

>     row = pg_fecharray( res, i );

$row = pg_fecharray( $res, $i );

>     /* do your stuff here */
>   }
> } else {
>   /* report error or whatever */
> }
>
> Nix.


Cheers,


John Clark


--
     /) John Clark Naldoza y Lopez                           (\
    / )    Software Design Engineer III                      ( \
  _( (_    _  Web-Application Development                    _) )_
 (((\ \>  /_>    Cable Modem Network Management System <_\  </ /)))
 (\\\\ \_/ /         NEC Telecom Software Phils., Inc.  \ \_/ ////)
  \       /                                              \       /
   \    _/  phone: (+63 32) 233-9142 loc. 3113            \_    /
   /   /  cellphone: (+63 919) 399-4742                     \   \
  /   / email: njclark@ntsp.nec.co.jp                        \   \


"Intelligence is the ability to avoid doing work, yet getting the work
done"
--Linus Torvalds

Re: PHP Related Problem

От
Keary Suska
Дата:
> From: John Clark Naldoza y Lopez <njclark@ntsp.nec.co.jp>
>> Hint: You cannot use a database handle as a global variable outside of its
>> native scope in certain versions of PHP. 4.0.6 corrects this problem.
>>
>
> Yes, you can...  I'm using the pgsql.inc from the MRBS
> (http://mrbs.sourceforge.net) guys, and I am using 4.0.4pl1 =)

Yes, my statement was not entirely accurate--you *can*, however under
certain situations, especially, if I recall correctly, that you are
including a file which includes a file trying to use the global, that it
will almost always fail in PHP 4.0.4. This is a known bug listed in the PHP
buglist database, but obviously not the problem you were experiencing.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"