note 19173 modified in function.pg-connect by ronabop

From: Date: Tue, 04 Feb 2003 04:36:31 +0000
Subject: note 19173 modified in function.pg-connect by ronabop
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-43364@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 PostgreSQL database !? What if your username or password changes? Create a connection include file. --- connection.inc --- <?php $connection = pg_connect("host=localhost port=5432 dbname=DATABASENAME user=USERNAME password=PASSWORD") or die ("Nao consegui conectar ao PostGres --> " . pg_last_error($conn)); ?> // 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 THEN start your SQL Job :) $result=pg_exec("SELECT field FROM table WHERE field = '$something' "); // Sample of SQL QUERY $fetch = pg_fetch_row($query_st); // Sample of SQL QUERY pg_close($connection); // Close this connection ?> []´s Helio Ferenhof d-m@eudoramail.com --was-- _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 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

« previous php.notes (#43364) next »