php-general Digest 1 May 2011 20:28:24 -0000 Issue 7292
Topics (messages 312607 through 312609):
Re: postgresql database access failure
312607 by: e-letter
312608 by: Ashley Sheridan
312609 by: e-letter
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On 30/04/2011, Daniel Brown <[email protected]> wrote:
> Readers? Sounds like you spend too much time writing newsletters
> (to the wrong address, since [email protected] is
> a self-help command list for digest-form subscriptions). ;-P
>
> On Sat, Apr 30, 2011 at 04:41, e-letter <[email protected]> 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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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..!
--- End Message ---