noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 05/39: Code : add connection by DSN


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 05/39: Code : add connection by DSN
Date: Sat, 11 Jul 2020 13:20:36 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 741a1c1417b4ba5443af24e300d09b0b3173651f
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Mon May 11 00:10:23 2020 +0200

    Code : add connection by DSN
---
 include/lib/database_core.class.php | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/lib/database_core.class.php 
b/include/lib/database_core.class.php
index 098b7d6..4e4bac2 100644
--- a/include/lib/database_core.class.php
+++ b/include/lib/database_core.class.php
@@ -77,6 +77,42 @@ class DatabaseCore
         $this->is_open = TRUE;
 
     }
+    /**
+     * Connect by DSN : description of database connection like 
+     * return a Database_Core object
+     * @code
+     *  port=6002 host=x.x.x.x dbname=dbname user=admin password=www
+     * @endcode
+     * 
+     * @param string $p_dsn describing the connection
+     * 
+     */
+    function connect_dsn($p_dsn) 
+    {
+        $this->db =pg_connect($p_dsn);
+
+        if ( $this->db == false )
+        {
+            if (DEBUG) {
+            echo '<h2 class="error">Impossible de se connecter &agrave; 
postgreSql !</h2>';
+            echo '<p>';
+            echo "Vos param&egrave;tres sont incorrectes : <br>";
+            echo "<br>";
+            echo "base de donn&eacute;e : $p_dsn<br>";
+            echo '</p>';
+
+            exit ("Connection impossible : v&eacute;rifiez vos 
param&egrave;tres de base
+                  de donn&eacute;es");
+            } else {
+                echo '<h2 class="error">' . _('Erreur de connexion !') . 
'</h2>';
+                $this->is_open = false;
+                throw new Exception(_('Erreur Connexion'));
+            }
+
+        }
+        $this->is_open=TRUE;
+        return $this;
+    }
 
     public function verify()
     {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]