note 19173 added to function.pg-connect
| From: | Helio Ferenhof | Date: | Mon, 18 Feb 2002 18:20:34 +0000 |
| Subject: | note 19173 added to function.pg-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26755@lists.php.net to get a copy of this message | ||
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Connection Hint
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Do you always write at the code the username and password to connect to your PosGres database !?
If your username or password change ? What do you do ? - Change in all php files??? Are you Crazy
?!?
Use this tip =)
Create a connection.inc and include it in all php that you need to connect to PostGres !!!
If you have to change the username or password just change at the connection.inc file!!!
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Here is the Sample
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
---
connection.inc
---
<?php
$connection = pg_connect("host=localhost port=5432 dbname=DATABASENAME user=USERNAME
password=PASSWORD")
or die ("Nao consegui conectar ao PostGres --> " . pg_errormessage($conn));
?>
// Use your username / PASSWORD / databasename
// you can use $database name and pass it from the php file :) If you connect into different
databases.
---
Phpfile.php
---
<?php
include('connection.php'); // Include the connection to the databank THAN start your SQL
Job :)
$result=pg_exec("SELECT field FROM table WHERE filed = '$something' "); //
Sample of SQL QUERY
$fetch = pg_fetch_row($query_st); // Sample of SQL QUERY
pg_close($connection); // Close this connection
?>
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
I hope it could help you!
[]´s
Helio Ferenhof
d-m@eudoramail.com
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
--
http://www.php.net/manual/en/function.pg-connect.php
http://master.php.net/manage/user-notes.php?action=edit+19173
http://master.php.net/manage/user-notes.php?action=delete+19173
http://master.php.net/manage/user-notes.php?action=reject+19173