Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I run PHP program in Linux and connect to PostgrSQL DB 1

Status
Not open for further replies.

gglgokop1704

Programmer
Aug 9, 2007
54
GB
Dear All,

Please I have written a php program to connect to a PostgreSQL database and select contents of a table and print it on the browser. But I could not run the program. I don't know how to run it or perhaps how to activate the php. I have done some configurations on httpd.conf and php.ini files. See the program below:

<?php
// Connecting, selecting database
$dbconn = pg_connect("host=138.250.104.227 dbname=rftDatabase user=globus password=globususer");


// Performing SQL query
$query = 'SELECT * FROM Criteria_Parameters';
$result = pg_query($query);

// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);
?>

Any help is appreciated
Regards
Gokop
 
Hi Greg,

Thanks for your response. I am not getting any error yet. It seems it is not running or I have not activated the PHP I installed on my Linux cluster. I have never installed PHP and I just followed the installation and configuration steps. It just opened the .php program and displayed the codes. When I added <html>, <head>, <title> and <body> elements to the code, it said this is a php program but it is showing html tags.

Please how can I put a php program in a function and whem I click a button, the onClick action should trigger this function to connect to postgrsql database, select a table and display on the web page.

Sorry for the lengthy explanation

Kind regards
Gokop
 
Sounds like PHP is not enabled on your webserver; or if it is enabled, you haven't restarted the webserver for these changes to take effect.

In any case, your script looks correct, syntax-wise, and therefore I don't think this is a PHP issue you are having. I would try posting this link in a webserver forum, or read the manual here:


That manual is for apache2.0 on linux, but with a little help from Google, should be able to find a document that will assist you.

Greg
 
How are you calling your PHP page?

It should something like:

If you are just opening the file directly, then it won't work.

to test that PHP is actually running, just lace this into a page: and call it using your browser and the format I posted above:
Code:
<?PHP
phpinfo();
?>

You should get a bunch of information about your PHP installation.

If you don't it means your PHP is not running.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Greg,

That is exactly the documentation I used to install/configure the PHP. Apache means Apache-Ant? I have apache-ant 1.7.0 installed during globus installation. Any way I successfully installed and configured PHP. If I have php installed, running a .php program I guess is simply double-clicking the .php program.

Thanks for your help

Kind regards
Gokop
 
You can't run php pages just by double clicking them, either you feed them to the php parser through the command prompt, or call them up via the webserver.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top