Re: [PHP] postgresql database access failure

2011-05-02 Thread e-letter
The query was:

$query = 'SELECT * FROM databasetablename';

So, database access seems to be the problem. Using the superuser
account 'postgres', a user 'httpd' was created and all privileges were
granted to the target database using the postgresql 'grant' command.
However the user 'httpd' is not the owner of the database so perhaps
that is the problem, although if this user could not access the
database that would cause an error in the log (but no such error is
seen)?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] postgresql database access failure

2011-05-01 Thread e-letter
On 30/04/2011, Daniel Brown danbr...@php.net wrote:
 Readers?  Sounds like you spend too much time writing newsletters
 (to the wrong address, since php-general-digest-h...@lists.php.net is
 a self-help command list for digest-form subscriptions).  ;-P

 On Sat, Apr 30, 2011 at 04:41, e-letter inp...@gmail.com wrote:
?php
$db = pg_connect('dbname=databasename user=username');
$query = 'SELECT * FROM databasename';
$value=pg_fetch_result($query,1,0);
echo 'export of database is ',$value,'';
?
p
why does this fail?

 How is it failing?  What error(s) are you seeing on screen or in
 your log files?  Noting that $value would contain an array, is that
 the problem?  And why are you using ending quotes in your echo?  You
 should just place the semicolon immediately after $value.


I looked at the error file located at '/var/log/httpd/error_log',
which identifies an error:

...Apache/2.2.6 (Mandriva Linux/PREFORK-8.2mdv2008.0) PHP/5.2.4 with
Suhosin-Patch mod_put/2.0.8 configured -- resuming normal
operations...

...PHP Parse error:  syntax error, unexpected T_VARIABLE, expecting
',' or ';'...

The file was changed as follows which caused the parse error shown above:

?php
$db = pg_connect('dbname=webcuttings user=httpd');
$query = 'SELECT * FROM articles';
$value=pg_fetch_result($query);
echo 'all files' $value;
?

The file was copied from the manual page, without understanding that
an array was being used.

/p
/body
 /html

 The following php code produces the user agent:

?php
echo '$_SERVER['HTTP_USER_AGENT']';
?

 First of all, no it doesn't.  Placed inside single quotes, it'll
 not only try to return it verbatim (i.e. - the variable would be
 printed to screen), but it'll also cause a parse error, as you reuse
 single quotes in the variable key container.


My mistake; with the command:

?php
echo $_SERVER['HTTP_USER_AGENT'];
?

the result is:

Opera/9.80 (X11; Linux i686; U; en-GB) Presto/2.6.30 Version/10.61

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] postgresql database access failure

2011-05-01 Thread Ashley Sheridan
On Sun, 2011-05-01 at 09:24 +0100, e-letter wrote:

 I looked at the error file located at '/var/log/httpd/error_log',
 which identifies an error:
 
 ...Apache/2.2.6 (Mandriva Linux/PREFORK-8.2mdv2008.0) PHP/5.2.4 with
 Suhosin-Patch mod_put/2.0.8 configured -- resuming normal
 operations...
 
 ...PHP Parse error:  syntax error, unexpected T_VARIABLE, expecting
 ',' or ';'...
 
 The file was changed as follows which caused the parse error shown
 above:
 
 ?php
 $db = pg_connect('dbname=webcuttings user=httpd');
 $query = 'SELECT * FROM articles';
 $value=pg_fetch_result($query);
 echo 'all files' $value;
 ?
 
 The file was copied from the manual page, without understanding that
 an array was being used. 


The problem you've got there is a missing string concatenator in your
echo line. You should change that line to read:

echo 'all files' . $value;

note the . character? However, as you said, $value is actually an array,
so you would be better of using something like print_r() or var_dump()
on it. 

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] postgresql database access failure

2011-05-01 Thread e-letter
The file was changed:

... $value=pg_fetch_result($query,1,1);
echo 'all files' . var_dump($value);
...

The resultant web page produces:

bool(false) all files

The php file was changed again:

... $value=pg_fetch_result($query);
echo 'all files' . var_dump($value);
...

The resultant web page produces:

NULL all files

The error log shows:

...PHP Warning:  pg_fetch_result(): supplied argument is not a valid
PostgreSQL result resource...

The objective is to learn how to extract data from a database and
print to a web browser, but not much progress made so far..!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] postgresql database access failure

2011-05-01 Thread David Robley
e-letter wrote:

 The file was changed:
 
 ...   $value=pg_fetch_result($query,1,1);
 echo 'all files' . var_dump($value);
 ...
 
 The resultant web page produces:
 
 bool(false) all files
 
 The php file was changed again:
 
 ...   $value=pg_fetch_result($query);
 echo 'all files' . var_dump($value);
 ...
 
 The resultant web page produces:
 
 NULL all files
 
 The error log shows:
 
 ...PHP Warning:  pg_fetch_result(): supplied argument is not a valid
 PostgreSQL result resource...
 
 The objective is to learn how to extract data from a database and
 print to a web browser, but not much progress made so far..!

There is a good example of how to use pg_fetch_result in the docs at
http://php.net/manual/en/function.pg-fetch-result.php.

On the basis of the code shown here, it's a bit hard to determine exactly
what your problem is; however the odds are that the error supplied
argument is not a valid PostgreSQL result resource results from a SQL
syntax error, or possibly that you have failed to open a connection to
pgsql. However, there are some tools to help you; see
http://php.net/manual/en/function.pg-result-error.php

For future reference, it helps to post all the code that is relevant to your
problem, so in this case it would help, for example, to see how you are
making the connection to pgsql and how the $query variable is populated.



Cheers
-- 
David Robley

A seminar on Time Travel will be held two weeks ago.
Today is Boomtime, the 49th day of Discord in the YOLD 3177. 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] postgresql database access failure

2011-04-30 Thread Daniel Brown
Readers?  Sounds like you spend too much time writing newsletters
(to the wrong address, since php-general-digest-h...@lists.php.net is
a self-help command list for digest-form subscriptions).  ;-P

On Sat, Apr 30, 2011 at 04:41, e-letter inp...@gmail.com wrote:
        ?php
                $db = pg_connect('dbname=databasename user=username');
                $query = 'SELECT * FROM databasename';
                $value=pg_fetch_result($query,1,0);
                echo 'export of database is ',$value,'';
        ?
        p
                why does this fail?

How is it failing?  What error(s) are you seeing on screen or in
your log files?  Noting that $value would contain an array, is that
the problem?  And why are you using ending quotes in your echo?  You
should just place the semicolon immediately after $value.

        /p
        /body
 /html

 The following php code produces the user agent:

        ?php
                echo '$_SERVER['HTTP_USER_AGENT']';
        ?

First of all, no it doesn't.  Placed inside single quotes, it'll
not only try to return it verbatim (i.e. - the variable would be
printed to screen), but it'll also cause a parse error, as you reuse
single quotes in the variable key container.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] postgresql database access failure

2011-04-30 Thread Daniel Brown
On Sat, Apr 30, 2011 at 12:23, Daniel Brown danbr...@php.net wrote:

        ?php
                echo '$_SERVER['HTTP_USER_AGENT']';
        ?

    First of all, no it doesn't.  Placed inside single quotes, it'll
 not only try to return it verbatim (i.e. - the variable would be
 printed to screen), but it'll also cause a parse error, as you reuse
 single quotes in the variable key container.

Forgot the second of all before hitting send.

Second of all, what does this have to do with your PostgreSQL
problem?  Did I miss something?

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php