Example #1
0
 /**
 *  Return all the fields of a table.
 *
 * It also populate the metadata array attribute will all the informations about the
 * table fields. Type, Key, Extra, Null
 * TABLE_QUALIFIER    
    TABLE_SCHEM
    TABLE_NAME
    COLUMN_NAME
    DATA_TYPE
    TYPE_NAME
    PRECISION
    LENGTH
    SCALE
    RADIX
    NULLABLE
    REMARKS
 *
 * @param string $table Name of the Table
 * @return array $field  All the fields name
 */
 function getTableField($table = "")
 {
     if (is_array($table)) {
         $atable = $table;
     } elseif (strlen($table) > 0) {
         $atable = $table;
     } else {
         $atable = $this->table;
     }
     if (is_array($atable)) {
         reset($atable);
         $numfields = 0;
         while (list($key, $table) = each($atable)) {
             //$table_def = mysql_query("SHOW FIELDS FROM $table", );
             $table_def = odbc_columns($this->dbCon->id, $this->dbCon->getDatabase(), "%", $table);
             for ($i = 0; $i < odbc_num_rows($table_def); $i++) {
                 $row_table_def = odbc_fetch_array($table_def);
                 $field[$numfields] = $row_table_def["COLUMN_NAME"];
                 $fieldname = $row_table_def["COLUMN_NAME"];
                 $this->metadata[$table][$fieldname]["Type"] = $row_table_def["TYPE_NAME"];
                 $this->metadata[$table][$fieldname]["Null"] = $row_table_def["NULLABLE"];
                 $this->metadata[$table][$fieldname]["Key"] = $row_table_def["SCALE"];
                 //not sure of that one.
                 $this->metadata[$table][$fieldname]["Extra"] = $row_table_def["REMARKS"];
                 $numfields++;
             }
         }
     } else {
         $table_def = odbc_columns($this->dbCon->id, $this->dbCon->getDatabase(), "%", $atable);
         for ($i = 0; $i < odbc_num_rows($table_def); $i++) {
             $row_table_def = odbc_fetch_array($table_def);
             $field[$i] = $row_table_def["COLUMN_NAME"];
             $fieldname = $row_table_def["COLUMN_NAME"];
             $this->metadata[$table][$fieldname]["Type"] = $row_table_def["TYPE_NAME"];
             $this->metadata[$table][$fieldname]["Null"] = $row_table_def["NULLABLE"];
             $this->metadata[$table][$fieldname]["Key"] = $row_table_def["SCALE"];
             //not sure of that one.
             $this->metadata[$table][$fieldname]["Extra"] = $row_table_def["REMARKS"];
         }
     }
     reset($field);
     return $field;
 }
Example #2
0
 /**
  * Execute an sqlQuery.
  *
  * Execute a query the query string and database connexion object need
  * to be passe has parameters or be previously define.
  *
  * @param string $sql   String with the SQL Query.
  * @param object sqlConnect $dbCon   Connexion object if not previously define in the contructor.
  * @return ResultSet $rquery
  * @access public
  */
 function query($sql = "", $dbCon = 0)
 {
     if ($dbCon != 0) {
         $this->dbCon = $dbCon;
     }
     if (strlen($sql) > 0) {
         $this->sql_query = trim($sql);
     }
     if (!is_resource($this->dbCon->id)) {
         $this->setError("Query Error: No open or valid connexion has been provide to execute the query: " . $this->sql_query);
         return false;
     }
     if (empty($this->sql_query)) {
         //    $this->setError("No query to execute.:".var_export(get_object_vars($this), true));
         $this->setLog(" query(): No query to execute.");
         return false;
     }
     if ($this->max_rows) {
         if (!$this->pos) {
             $this->pos = 0;
         }
         $qpos = " limit " . $this->pos . ", " . $this->max_rows;
     } else {
         if (!$this->pos) {
             $this->pos = "";
         }
         $qpos = $this->pos;
     }
     /** Temporary for ";" compatibility with postgresql **/
     //  if (substr($this->sql_query, -1,1) == ";") {
     //      $this->sql_query = substr($this->sql_query, 0, strlen($this->sql_query)-1) ;
     //  }
     // This is to fix the mysql_select_db problem when connexion have same username.
     if ($this->dbCon->getAllwaysSelectDb()) {
         $this->dbCon->setDatabase($this->dbCon->getDatabase());
         //echo $this->dbCon->getDatabase();
     }
     // convert quote from postgresql queries
     // this was a bad idea, break wordpress install for example!!!
     //$this->sql_query=str_replace('"', '`',$this->sql_query);
     if ($this->dbCon->getUseCluster()) {
         if (preg_match("/^select/i", $this->sql_query)) {
             $this->query_connexion = $this->dbCon->id;
         } else {
             $this->query_connexion = $this->dbCon->wid;
         }
     } else {
         $this->query_connexion = $this->dbCon->id;
     }
     if (preg_match("/^select/i", $this->sql_query)) {
         $rquery = mysql_query($this->sql_query . " " . $this->sql_order . " " . $qpos, $this->query_connexion);
         $this->setLog($this->sql_query . " " . $this->sql_order . " " . $qpos);
     } else {
         $rquery = mysql_query($this->sql_query, $this->query_connexion);
         $this->setLog($this->sql_query);
     }
     $sqlerror = "";
     if (!is_resource($rquery)) {
         $sqlerror = mysql_error($this->query_connexion);
         if (!empty($sqlerror)) {
             $this->setError("<b>SQL Query Error :</b>" . mysql_errno($this->query_connexion) . " - " . $sqlerror . " (" . $this->sql_query . ")");
         }
     }
     if (!$this->max_rows) {
         $this->num_rows = @mysql_num_rows($rquery);
     }
     //$this->insert_id = mysql_insert_id() ;
     $this->insert_id = 0;
     $this->result = $rquery;
     $this->cursor = 0;
     if ($this->dbCon->getBackupSync()) {
         if (preg_match("/^alter/i", $this->sql_query) || preg_match("/^create/i", $this->sql_query) || preg_match("/^drop/i", $this->sql_query)) {
             if ($this->dbCon->getUseDatabase()) {
                 $qInsSync = "insert into " . $this->dbCon->getTableBackupSync() . " ( actiontime, sqlstatement, dbname) values ( '" . time() . "', '" . addslashes($this->sql_query) . "', '" . $this->dbCon->db . "') ";
                 $rquery = mysql_query($qInsSync, $this->dbCon->id);
             } else {
                 $file = $this->dbCon->getProjectDirectory() . "/" . $this->dbCon->getTableBackupSync() . ".struct.sql";
                 $fp = fopen($file, "a");
                 $syncquery = $this->sql_query . ";\n";
                 fwrite($fp, $syncquery, strlen($syncquery));
                 fclose($fp);
             }
         }
         if (preg_match("/^insert/i", $this->sql_query) || preg_match("/^update/i", $this->sql_query) || preg_match("/^delete/i", $this->sql_query)) {
             if ($this->dbCon->getUseDatabase()) {
                 $qInsSync = "insert into " . $this->dbCon->getTableBackupSync() . " ( actiontime, sqlstatement, dbname) values ( '" . time() . "', '" . addslashes($this->sql_query) . "', '" . $this->dbCon->db . "') ";
                 $rquery = mysql_query($qInsSync, $this->dbCon->id);
             } else {
                 $file = $this->dbCon->getProjectDirectory() . "/" . $this->dbCon->getTableBackupSync() . ".data.sql";
                 $fp = fopen($file, "a");
                 $syncquery = $this->sql_query . ";\n";
                 fwrite($fp, $syncquery, strlen($syncquery));
                 fclose($fp);
             }
         }
     }
     return $rquery;
 }
Example #3
0
//  Change the default events parameters times out
//  $cfg_event_param_garbage_time_out = 3600;
//  $cfg_event_param_garbage_interval = 3400;
//Radria usage statistics:
$cfg_radria_stat_usage = true;
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (file_exists($GLOBALS['cfg_full_path'] . 'includes/extraconfig.inc.php')) {
    include_once $GLOBALS['cfg_full_path'] . 'includes/extraconfig.inc.php';
}
$cfg_web_path = dirname($_SERVER['PHP_SELF']);
if (!ereg("/\$", $cfg_web_path)) {
    $cfg_web_path .= "/";
}
session_set_cookie_params(0, $cfg_web_path);
session_start();
//include("includes/lang_".$cfg_lang.".inc.php") ;
//$_SESSION["cfg_lang"] = $cfg_lang ;
// Database connexions :
//Uncomment bellow if you plan to use a database
$conx = new sqlConnect("@login", "@password");
$conx->setHostname("@hostname");
$conx->setDatabase("@database");
// Directory where pas is located
$conx->setBaseDirectory($cfg_local_pasdir);
// Directory where the project is located unless your config.php file is outside your project tree is should be "./"
$conx->setProjectDirectory($cfg_full_path . "./");
//$conx->start() ;
include "includes/globalvar.inc.php";
if (file_exists("includes/extraconfig_postdb.inc.php")) {
    include_once "includes/extraconfig_postdb.inc.php";
}
Example #4
0
$cfg_notrefererequestkey = "XX5X5XC7C5CFF7FC7C65FCD7FGGFD7FR22462";
//Radria anonymous usage statistics:
$cfg_radria_stat_usage = true;
// Turn off errors display on production site
// or when using the pas pagebuilder
//error_reporting(0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (file_exists($GLOBALS['cfg_full_path'] . 'includes/extraconfig.inc.php')) {
    include_once $GLOBALS['cfg_full_path'] . 'includes/extraconfig.inc.php';
}
$cfg_web_path = dirname($_SERVER['PHP_SELF']);
if (!ereg("/\$", $cfg_web_path)) {
    $cfg_web_path .= "/";
}
session_set_cookie_params(0, $cfg_web_path);
session_start();
//include("includes/lang_".$cfg_lang.".inc.php") ;
//$_SESSION["cfg_lang"] = $cfg_lang ;
// Database connexions :
$conx = new sqlConnect("radria", "sample");
$conx->setHostname("localhost");
$conx->setDatabase("RadriaSample");
// Directory where pas is located
$conx->setBaseDirectory($cfg_local_pasdir);
// Directory where the project is located unless your config.php file is outside your project tree is should be "./"
$conx->setProjectDirectory($cfg_full_path . "./");
$conx->start();
include "includes/globalvar.inc.php";
if (file_exists("includes/extraconfig_postdb.inc.php")) {
    include_once "includes/extraconfig_postdb.inc.php";
}
Example #5
0
 /**
  * Merge and send an email message with the content of
  * an executed sqlQuery .
  *
  *  @param sqlConnect $query executed sqlQuery
  *  @see getField()
  */
 function fusion($query)
 {
     $numsent = 0;
     set_time_limit(3600);
     while ($row = $query->fetchArray()) {
         $numsent++;
         $fields = $this->getField($this->mBody);
         $fields = $this->getField($this->mBodyHtml);
         $SendBody = $this->mBody;
         $SendBodyHtml = $this->mBodyHtml;
         $SendSubject = $this->mSubject;
         if (is_array($fields)) {
             foreach ($fields as $field) {
                 $SendBody = eregi_replace("\\[{$field}\\]", $row[$field], $SendBody);
                 $SendBodyHtml = eregi_replace("\\[{$field}\\]", $row[$field], $SendBodyHtml);
                 $SendSubject = eregi_replace("\\[{$field}\\]", $row[$field], $SendSubject);
             }
         }
         $SendBody = ereg_replace("\r", "", $SendBody);
         $this->setHeader();
         if (strlen($SendBodyHtml) > 5) {
             $this->sendMailHtml($row[$this->cfgEmailField], $SendSubject, $SendBody, $SendBodyHtml, $this->header);
         } elseif (strlen($this->file) > 0 && strlen($this->filename) > 0) {
             $this->sendMailJoin($row[$this->cfgEmailField], $SendSubject, $SendBody, $this->file, $this->filename, $this->header);
         } else {
             $this->sendMailStandard($row[$this->cfgEmailField], $SendSubject, $SendBody, $this->header);
         }
         //if (is_integer($numsent/10)) { echo ".";}
         //if (is_integer($numsent/100)) {echo $numsent." <br>\n"; }
     }
     return $numsent;
 }
Example #6
0
 /**
  * Execute an sqlQuery
  *
  * Execute a query the query string and database connexion object need
  * to be passe has parameters or be previously define
  *
  * @param sting $sql   String with the SQL Query
  * @param object sqlConnect $dbCon   Connexion object if not previously define in the contructor
  * @return ResultSet $rquery
  * @access public
  */
 function query($sql = "", $dbCon = 0)
 {
     if ($dbCon != 0) {
         $this->dbCon = $dbCon;
     }
     if (strlen($sql) > 0) {
         $this->sql_query = trim($sql);
     }
     if (!is_resource($this->dbCon->id)) {
         $this->setError("Query Error: No open or valid connexion has been provide to execute the query: " . $this->sql_query);
     }
     //    if ($this->sql_query == "") {
     //      if (is_array($this->table)) {
     //        reset($this->table) ;
     //        $this->sql_query = "select * from " ;
     //        while (list($key, $table) = each($this->table)) {
     //          $this->sql_query .= $table."," ;
     //        }
     //        $this->sql_query = ereg_replace(",$", "", $this->sql_query) ;
     //      } else {
     //        $this->sql_query= "select * from $this->table" ;
     //      }
     //    }
     if (empty($this->sql_query)) {
         $this->setError("No query to execute");
         return false;
     }
     if ($this->max_rows) {
         if (!$this->pos) {
             $this->pos = 0;
         }
         // $qpos = " limit ".$this->pos.", ".$this->max_rows ; PL oposite of MySQL
         $qpos = " limit " . $this->max_rows . " offset " . $this->pos;
     } else {
         if (!$this->pos) {
             $this->pos = "";
         }
         $qpos = $this->pos;
     }
     // convert quote from mysql queries
     // This will need to be removed as it may generate significant problem is queries uses backquotes
     // in their content
     $this->sql_query = str_replace('`', '"', $this->sql_query);
     $rquery = pg_query($this->dbCon->id, "{$this->sql_query} {$this->sql_order} {$qpos}");
     if (!is_resource($rquery)) {
         $sqlerror = pg_last_error();
         if ($sqlerror) {
             $this->setError("<b>SQL Query Error :</b>" . $sqlerror . " ({$this->sql_query} {$this->sql_order} {$qpos})");
         }
     } else {
         //    if (!$this->max_rows) {  PL 20020920 commented out to make it work on the fetch()
         $this->num_rows = @pg_numrows($rquery);
         //   }
     }
     //$this->insert_id =  pg_getlastoid($rquery) ;
     $this->result = $rquery;
     $this->cursor = 0;
     if ($this->dbCon->getBackupSync()) {
         if (eregi("^alter", $this->sql_query) || eregi("^create", $this->sql_query) || eregi("^drop", $this->sql_query)) {
             if ($this->dbCon->getUseDatabase()) {
                 $qInsSync = "insert into " . $this->dbCon->getTableBackupSync() . " ( actiontime, sqlstatement, dbname) values ( '" . time() . "', '" . addslashes($this->sql_query) . "', '" . $this->dbCon->db . "') ";
                 $rquery = pg_query($this->dbCon->db, $qInsSync, $this->dbCon->id);
             } else {
                 $file = $this->dbCon->getProjectDirectory() . "/" . $this->dbCon->getTableBackupSync() . ".struct.sql";
                 $fp = fopen($file, "a");
                 $syncquery = $this->sql_query . ";\n";
                 fwrite($fp, $syncquery, strlen($syncquery));
                 fclose($fp);
             }
         }
         if (eregi("^insert", $this->sql_query) || eregi("^update", $this->sql_query) || eregi("^delete", $this->sql_query)) {
             if ($this->dbCon->getUseDatabase()) {
                 $qInsSync = "insert into " . $this->dbCon->getTableBackupSync() . " ( actiontime, sqlstatement, dbname) values ( '" . time() . "', '" . addslashes("{$this->sql_query} {$this->sql_order} {$qpos}") . "', '" . $this->dbCon->db . "') ";
                 $rquery = pg_query($this->dbCon->db, $qInsSync, $this->dbCon->id);
             } else {
                 $file = $this->dbCon->getProjectDirectory() . "/" . $this->dbCon->getTableBackupSync() . ".data.sql";
                 $fp = fopen($file, "a");
                 $syncquery = $this->sql_query . ";\n";
                 fwrite($fp, $syncquery, strlen($syncquery));
                 fclose($fp);
             }
         }
     }
     return $rquery;
 }