note 19173 deleted from function.pg-connect by kalle

From: Date: Mon, 12 Jan 2015 20:09:41 +0000
Subject: note 19173 deleted from function.pg-connect by kalle
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201415@lists.php.net to get a copy of this message
Note Submitter: Helio Ferenhof <d-m at eudoramail dot com> ---- 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

« previous php.notes (#201415) next »