]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Trying to implement database class
authorJean-Marc Pigeon <jmp@safe.c>
Sun, 31 Aug 2025 12:18:49 +0000 (08:18 -0400)
committerJean-Marc Pigeon <jmp@safe.c>
Sun, 31 Aug 2025 12:18:49 +0000 (08:18 -0400)
www/devsql.php
www/mailleur.php
www/subrou.php
www/unipos.php

index ce31e6c8f2c345c5a702c7f3de9c32c2b3a652f1..0387445e5bf9b9d79d8df255e1ea320b31c6fb55 100644 (file)
@@ -5,9 +5,27 @@
 //
 //==============================================================
 
+enum dbtype    {
+               case mysql;
+               case postgres;
+               case unknowdb;  
+               }
+
+
+class dbinfo   {
+               public dbtype $dbspec;
+               public object $sqlptr;
+               }
+
+//==============================================================
+//
+//     To open (according DBTYP) A database acces
+//
+//==============================================================
 function sql_connect() 
 
 {
+$dbinfo=new dbinfo();
 $conn=0;
 $dbusr=getenv("APPNAME");
 $dbtype=getenv("DB_TYPE");
@@ -17,30 +35,37 @@ $dbport=getenv("DB_PORT");
 switch($dbtype) {
   case 'MYSQL'         :
     include_once "unimar.php";
-    $conn=mar_connect($dbhost,$dbusr,$dbname,$dbport);
+    $dbinfo->dbspec=mysql;
+    $dbinfo->sqlptr=mar_connect($dbhost,$dbusr,$dbname,$dbport);
     break;
   case 'POSTGRESQL'    :
     include_once "unipos.php";
-    $conn=pos_connect($dbhost,$dbusr,$dbname,$dbport);
+    //$dbinfo->dbspec=postgres;
+    $dbinfo->sqlptr=(object)pos_connect($dbhost,$dbusr,$dbname,$dbport);
     break;
   default              :
+    unset($dbinfo);
     $daterr="Connect Database, type <".$dbtype."> is unexpected!";
     throw new ErrorException($daterr);
     break;
   }
-return $conn;
+return $dbinfo;
 }
 
-function sql_close($conn) 
+//==============================================================
+//
+//     To close  database acces previously access
+//
+//==============================================================
+function sql_close(dbinfo $dbinfo) 
 
 {
-$dbtype=getenv("DB_TYPE");
-switch($dbtype) {
+switch($dbinfo->dbspec) {
   case 'MYSQL'         :
     $STR=mar_close($conn);
     break;
   case 'POSTGRESQL'    :
-    $STR=pos_close($conn);
+    pos_close($dbinfo->$sqlptr);
     break;
   default              :
     $daterr="Close Database, type <".$dbtype."> is unexpected!";
@@ -49,4 +74,19 @@ switch($dbtype) {
   }
 return $STR;
 }
+
+//==============================================================
+//
+//     To do a SQL query to database
+//
+//==============================================================
+function sql_query($conn,$reqst)
+
+{
+$dbtype=getenv("DB_TYPE");
+}
+
+
+include_once "subrou.php";
+
 ?>
index 387480f069e0659abb6df8eb9354c451ff19c284..ae9fc47bd9c6de22fac83f3119b36f6294089960 100644 (file)
@@ -11,8 +11,8 @@ include_once "devsql.php";
 $footer=footer("mailleur");
 $dbtype=getenv("DB_TYPE");
 $conn=sql_connect();
+rou_alert(0,"bigre Bigre");
 sql_close($conn);
-rou_alert(0,"This a syslog message");
 rou_closelog();
 
 
index feb369ff947843d28e7639fe47034f1a5e462d44..96cad9b6010a4f481e6136c44791bebdf1ac2e41 100644 (file)
@@ -4,7 +4,7 @@
 //     To manage very low level function
 //
 //==============================================================
-global $debug;
+global $debug;
 
 
 $debug=0;
@@ -33,6 +33,8 @@ closelog();
 function rou_alert($dbglvl,$report)
 
 {
+global $debug;
+
 if ($debug>=$dbglvl)
   syslog(LOG_INFO,"$report");
 }
index a9c630d3ed650a3837ad8071c687157994961873..d0035c604cf63e262482f17371c22b94e1d33faf 100644 (file)
@@ -1,10 +1,40 @@
 <?php
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
 //==============================================================
 //
 //     To manage all access to Postgresql database
 //
 //==============================================================
-//
+
+class pgsql     {
+  private $connection = null;
+  // this function is called everytime this class is instantiated
+
+  public function __construct()        {
+    }
+
+       // Insert a row/s in a Database Table
+  public function Insert()     {
+    }  
+
+  // Select a row/s in a Database Table
+  public function Select()      {
+    }
+
+  // Update a row/s in a Database Table
+  public function Update( )     {
+    }    
+
+  // Remove a row/s in a Database Table
+  public function Remove( )     {
+  }    
+
+  // execute statement
+  private function executeStatement( ){
+    }
+
+  }
+
 //==============================================================
 //     To connect to a local/remote POSTGRESQL database
 //==============================================================
@@ -22,12 +52,13 @@ return $conn;
 //==============================================================
 //     To disconnect from a local/remote POSTGRESQL database
 //==============================================================
-function pos_close($conn)
+function pos_close(PgSql\Connection $sqlptr)
 
 {
 $OPEP="unipos, pos_close";
 
-pg_close($conn);
+pg_close($sqlptr);
+unset($sqlptr);
 return 0;
 }
 ?>