From: Jean-Marc Pigeon Date: Sun, 31 Aug 2025 13:53:02 +0000 (-0400) Subject: devsql class implementation begining X-Git-Tag: end-0.15~45 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=35374f8a730bb0f5a81d047dfa0c8f92813fa0d1;p=jmp%2Fmailleur devsql class implementation begining --- diff --git a/www/devsql.php b/www/devsql.php index 0387445..7bfd0f5 100644 --- a/www/devsql.php +++ b/www/devsql.php @@ -1,21 +1,56 @@ connection=new PDO("$dbtype:host={$dbhost};dbname={$dbname};",$dbuser); + $this->connection->setAttribute(PDO::ATTR_PERSISTENT,true); + $this->connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); + $this->connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); + } catch(Exception $e) { + throw new Exception($e->getMessage()); + } + } + + // disconnecting to database + public function __destruct() { + $this->connection = null; + rou_alert(0,"JMPDBG Disconnecting from database"); + } + + // 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( ){ + } + + } -class dbinfo { - public dbtype $dbspec; - public object $sqlptr; - } //============================================================== // @@ -25,30 +60,28 @@ class dbinfo { function sql_connect() { -$dbinfo=new dbinfo(); -$conn=0; -$dbusr=getenv("APPNAME"); +$OPEP="devsal.php, sql_connect"; + +$dbinfo=null; +$dbuser=getenv("APPNAME"); $dbtype=getenv("DB_TYPE"); $dbname=getenv("DB_NAME"); $dbhost=getenv("DB_HOST"); $dbport=getenv("DB_PORT"); switch($dbtype) { - case 'MYSQL' : - include_once "unimar.php"; - $dbinfo->dbspec=mysql; - $dbinfo->sqlptr=mar_connect($dbhost,$dbusr,$dbname,$dbport); +case 'MYSQL' : + $dbinfo=new devsql("mysql",$dbhost,$dbname,$dbuser); break; case 'POSTGRESQL' : - include_once "unipos.php"; - //$dbinfo->dbspec=postgres; - $dbinfo->sqlptr=(object)pos_connect($dbhost,$dbusr,$dbname,$dbport); + $dbinfo=new devsql("pgsql",$dbhost,$dbname,$dbuser); break; default : unset($dbinfo); $daterr="Connect Database, type <".$dbtype."> is unexpected!"; throw new ErrorException($daterr); break; - } +} +rou_alert(0,"$OPEP connect to database"); return $dbinfo; } @@ -57,22 +90,14 @@ return $dbinfo; // To close database acces previously access // //============================================================== -function sql_close(dbinfo $dbinfo) +function sql_close(devsql $dbinfo) { -switch($dbinfo->dbspec) { - case 'MYSQL' : - $STR=mar_close($conn); - break; - case 'POSTGRESQL' : - pos_close($dbinfo->$sqlptr); - break; - default : - $daterr="Close Database, type <".$dbtype."> is unexpected!"; - throw new ErrorException($daterr); - break; - } -return $STR; +$OPEP="devsql.php, sql_close"; + +rou_alert(0,"$OPEP JMPDBG desconnect database"); +sleep(10); +$dbinfo->connection=null; } //============================================================== diff --git a/www/mailleur.php b/www/mailleur.php index ae9fc47..8852900 100644 --- a/www/mailleur.php +++ b/www/mailleur.php @@ -34,7 +34,6 @@ Login=$logname Password=$pass
DBTYPE=$dbtype; DBPORT=$dbport -sql_connect=$mode
diff --git a/www/unipos.php b/www/unipos.php index d0035c6..f8c0856 100644 --- a/www/unipos.php +++ b/www/unipos.php @@ -11,6 +11,9 @@ class pgsql { // this function is called everytime this class is instantiated public function __construct() { + $this->connection = new PDO("mysql:host={$dbhost};dbname={$dbname};",$username); + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } // Insert a row/s in a Database Table