Example #1
0
function db_affected_rows($res)
{
    global $db_type;
    global $debug;
    global $_connect_id;
    if ($db_type == "mysql") {
        return mysql_affected_rows($_connect_id);
    } else {
        if ($db_type == "oracle") {
            return OCIRowCount($res);
        }
    }
}
 function affected_rows()
 {
     return OCIRowCount($this->Parse);
 }
 /**
  * db::free_results()
  * 
  * @return 
  **/
 function free_results()
 {
     global $GonxAdmin;
     switch ($GonxAdmin["dbtype"]) {
         case "mysql":
             return mysql_free_result($this->dbQryResult);
             break;
         case "postgresql":
             return pg_freeresult($this->dbQryResult);
             break;
         case "oracle":
             return OCIRowCount($this->Link_ID);
             break;
         case "sqlite":
             break;
         case "mssql":
             return mssql_free_result($this->dbQryResult);
             break;
     }
 }
Example #4
0
 function AffectedRowsCountEx()
 {
     return @OCIRowCount($this->result);
 }
Example #5
0
 /**
  * all the RDBMS specific things needed close a DB connection
  * 
  * @access private
  */
 function _doQuery($query, $first = 0, $limit = 0, $prepared_query = 0)
 {
     $lobs = 0;
     $success = MDB_OK;
     $result = 0;
     $descriptors = array();
     if ($prepared_query) {
         $columns = '';
         $variables = '';
         for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
             $position = key($this->clobs[$prepared_query]);
             if (gettype($descriptors[$position] = @OCINewDescriptor($this->connection, OCI_D_LOB)) != 'object') {
                 $success = $this->raiseError(MDB_ERROR, NULL, NULL, 'Do query: Could not create descriptor for clob parameter');
                 break;
             }
             $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['Fields'][$position - 1];
             $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':clob' . $position;
             $lobs++;
         }
         if (!MDB::isError($success)) {
             for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
                 $position = key($this->blobs[$prepared_query]);
                 if (gettype($descriptors[$position] = @OCINewDescriptor($this->connection, OCI_D_LOB)) != 'object') {
                     $success = $this->raiseError(MDB_ERROR, NULL, NULL, 'Do query: Could not create descriptor for blob parameter');
                     break;
                 }
                 $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['Fields'][$position - 1];
                 $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':blob' . $position;
                 $lobs++;
             }
             $query .= $columns . $variables;
         }
     }
     if (!MDB::isError($success)) {
         if ($statement = @OCIParse($this->connection, $query)) {
             if ($lobs) {
                 for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
                     $position = key($this->clobs[$prepared_query]);
                     if (!@OCIBindByName($statement, ':clob' . $position, $descriptors[$position], -1, OCI_B_CLOB)) {
                         $success = $this->oci8RaiseError(NULL, 'Do query: Could not bind clob upload descriptor');
                         break;
                     }
                 }
                 if (!MDB::isError($success)) {
                     for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
                         $position = key($this->blobs[$prepared_query]);
                         if (!@OCIBindByName($statement, ':blob' . $position, $descriptors[$position], -1, OCI_B_BLOB)) {
                             $success = $this->oci8RaiseError(NULL, 'Do query: Could not bind blob upload descriptor');
                             break;
                         }
                     }
                 }
             }
             if (!MDB::isError($success)) {
                 if ($result = @OCIExecute($statement, $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT)) {
                     if ($lobs) {
                         for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
                             $position = key($this->clobs[$prepared_query]);
                             $clob_stream = $this->prepared_queries[$prepared_query - 1]['Values'][$position - 1];
                             for ($value = ''; !$this->endOfLOB($clob_stream);) {
                                 if ($this->readLOB($clob_stream, $data, $this->getOption('lob_buffer_length')) < 0) {
                                     $success = $this->raiseError();
                                     break;
                                 }
                                 $value .= $data;
                             }
                             if (!MDB::isError($success) && !$descriptors[$position]->save($value)) {
                                 $success = $this->oci8RaiseError(NULL, 'Do query: Could not upload clob data');
                             }
                         }
                         if (!MDB::isError($success)) {
                             for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
                                 $position = key($this->blobs[$prepared_query]);
                                 $blob_stream = $this->prepared_queries[$prepared_query - 1]['Values'][$position - 1];
                                 for ($value = ''; !$this->endOfLOB($blob_stream);) {
                                     if ($this->readLOB($blob_stream, $data, $this->getOption('lob_buffer_length')) < 0) {
                                         $success = $this->raiseError();
                                         break;
                                     }
                                     $value .= $data;
                                 }
                                 if (!MDB::isError($success) && !$descriptors[$position]->save($value)) {
                                     $success = $this->oci8RaiseError(NULL, 'Do query: Could not upload blob data');
                                 }
                             }
                         }
                     }
                     if ($this->auto_commit) {
                         if ($lobs) {
                             if (MDB::isError($success)) {
                                 if (!@OCIRollback($this->connection)) {
                                     $success = $this->oci8RaiseError(NULL, 'Do query: ' . $success->getUserinfo() . ' and then could not rollback LOB updating transaction');
                                 }
                             } else {
                                 if (!@OCICommit($this->connection)) {
                                     $success = $this->oci8RaiseError(NULL, 'Do query: Could not commit pending LOB updating transaction');
                                 }
                             }
                         }
                     } else {
                         $this->uncommitedqueries++;
                     }
                     if (!MDB::isError($success)) {
                         switch (@OCIStatementType($statement)) {
                             case 'SELECT':
                                 $result_value = intval($statement);
                                 $this->current_row[$result_value] = -1;
                                 if ($limit > 0) {
                                     $this->limits[$result_value] = array($first, $limit, 0);
                                 }
                                 $this->highest_fetched_row[$result_value] = -1;
                                 break;
                             default:
                                 $this->affected_rows = @OCIRowCount($statement);
                                 @OCIFreeCursor($statement);
                                 break;
                         }
                         $result = $statement;
                     }
                 } else {
                     return $this->oci8RaiseError($statement, 'Do query: Could not execute query');
                 }
             }
         } else {
             return $this->oci8RaiseError(NULL, 'Do query: Could not parse query');
         }
     }
     for (reset($descriptors), $descriptor = 0; $descriptor < count($descriptors); $descriptor++, next($descriptors)) {
         @OCIFreeDesc($descriptors[key($descriptors)]);
     }
     return $result;
 }
Example #6
0
 public function getNumRows($name)
 {
     return OCIRowCount($this->result[$name]);
 }
Example #7
0
/**
 * Returns the number of rows affected by the last INSERT, UPDATE or DELETE.
 *
 * <b>Note:</b> Use the {@link dbi_error()} function to get error information
 * if the connection fails.
 *
 * @param resource $conn The database connection
 * @param resource $res  The database query resource returned from
 *                       the {@link dbi_query()} function.
 *
 * @return int The number or database rows affected.
 */
function dbi_affected_rows($conn, $res)
{
    if (strcmp($GLOBALS["db_type"], "mysql") == 0) {
        return mysql_affected_rows($conn);
    } else {
        if (strcmp($GLOBALS["db_type"], "mysqli") == 0) {
            return mysqli_affected_rows($conn);
        } else {
            if (strcmp($GLOBALS["db_type"], "mssql") == 0) {
                return mssql_affected_rows($conn);
            } else {
                if (strcmp($GLOBALS["db_type"], "oracle") == 0) {
                    if ($GLOBALS["oracle_statement"] >= 0) {
                        return OCIRowCount($GLOBALS["oracle_statement"]);
                    } else {
                        return -1;
                    }
                } else {
                    if (strcmp($GLOBALS["db_type"], "postgresql") == 0) {
                        return pg_affected_rows($res);
                    } else {
                        if (strcmp($GLOBALS["db_type"], "odbc") == 0) {
                            return odbc_num_rows($res);
                        } else {
                            if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) {
                                return db2_num_rows($res);
                            } else {
                                if (strcmp($GLOBALS["db_type"], "ibase") == 0) {
                                    return ibase_affected_rows($conn);
                                } else {
                                    dbi_fatal_error("dbi_free_result(): db_type not defined.");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 function query($query)
 {
     // For reg expressions
     $query = trim($query);
     $return_value = 0;
     // Flush cached values..
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Parses the query and returns a statement..
     if (!($stmt = OCIParse($this->dbh, $query))) {
         $this->print_error("Last Query", $query);
     } elseif (!($this->result = OCIExecute($stmt))) {
         $this->print_error("Last Query", $query);
     }
     $this->num_queries++;
     // If query was an insert
     if (preg_match('/^(insert|delete|update|create)\\s+/i', $query)) {
         // num afected rows
         $return_value = $this->rows_affected = OCIRowCount($stmt);
     } else {
         // Get column information
         if ($num_cols = @OCINumCols($stmt)) {
             // Fetch the column meta data
             for ($i = 1; $i <= $num_cols; $i++) {
                 $this->col_info[$i - 1]->name = OCIColumnName($stmt, $i);
                 $this->col_info[$i - 1]->type = OCIColumnType($stmt, $i);
                 $this->col_info[$i - 1]->size = OCIColumnSize($stmt, $i);
             }
         }
         // If there are any results then get them
         if ($this->num_rows = @OCIFetchStatement($stmt, $results)) {
             // Convert results into object orientated results..
             // Due to Oracle strange return structure - loop through columns
             foreach ($results as $col_title => $col_contents) {
                 $row_num = 0;
                 // then - loop through rows
                 foreach ($col_contents as $col_content) {
                     $this->last_result[$row_num]->{$col_title} = $col_content;
                     $row_num++;
                 }
             }
         }
         // num result rows
         $return_value = $this->num_rows;
     }
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_value;
 }
Example #9
0
 function DoQuery($query, $first = 0, $limit = 0, $prepared_query = 0)
 {
     $lobs = 0;
     $success = 1;
     $result = 0;
     $descriptors = array();
     if ($prepared_query) {
         $columns = "";
         $variables = "";
         for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
             $position = Key($this->clobs[$prepared_query]);
             if (GetType($descriptors[$position] = OCINewDescriptor($this->connection, OCI_D_LOB)) != "object") {
                 $this->SetError("Do query", "Could not create descriptor for clob parameter");
                 $success = 0;
                 break;
             }
             $columns .= ($lobs == 0 ? " RETURNING " : ",") . $this->prepared_queries[$prepared_query - 1]["Fields"][$position - 1];
             $variables .= ($lobs == 0 ? " INTO " : ",") . ":clob" . $position;
             $lobs++;
         }
         if ($success) {
             for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
                 $position = Key($this->blobs[$prepared_query]);
                 if (GetType($descriptors[$position] = OCINewDescriptor($this->connection, OCI_D_LOB)) != "object") {
                     $this->SetError("Do query", "Could not create descriptor for blob parameter");
                     $success = 0;
                     break;
                 }
                 $columns .= ($lobs == 0 ? " RETURNING " : ",") . $this->prepared_queries[$prepared_query - 1]["Fields"][$position - 1];
                 $variables .= ($lobs == 0 ? " INTO " : ",") . ":blob" . $position;
                 $lobs++;
             }
             $query .= $columns . $variables;
         }
     }
     if ($success) {
         if ($statement = OCIParse($this->connection, $query)) {
             if ($lobs) {
                 for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
                     $position = Key($this->clobs[$prepared_query]);
                     if (!OCIBindByName($statement, ":clob" . $position, $descriptors[$position], -1, OCI_B_CLOB)) {
                         $this->SetOCIError("Do query", "Could not bind clob upload descriptor", OCIError($statement));
                         $success = 0;
                         break;
                     }
                 }
                 if ($success) {
                     for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
                         $position = Key($this->blobs[$prepared_query]);
                         if (!OCIBindByName($statement, ":blob" . $position, $descriptors[$position], -1, OCI_B_BLOB)) {
                             $this->SetOCIError("Do query", "Could not bind blob upload descriptor", OCIError($statement));
                             $success = 0;
                             break;
                         }
                     }
                 }
             }
             if ($success) {
                 if ($result = @OCIExecute($statement, $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT)) {
                     if ($lobs) {
                         for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
                             $position = Key($this->clobs[$prepared_query]);
                             $clob_stream = $this->prepared_queries[$prepared_query - 1]["Values"][$position - 1];
                             for ($value = ""; !MetabaseEndOfLOB($clob_stream);) {
                                 if (MetabaseReadLOB($clob_stream, $data, $this->lob_buffer_length) < 0) {
                                     $this->SetError("Do query", MetabaseLOBError($clob));
                                     $success = 0;
                                     break;
                                 }
                                 $value .= $data;
                             }
                             if ($success && !$descriptors[$position]->save($value)) {
                                 $this->SetOCIError("Do query", "Could not upload clob data", OCIError($statement));
                                 $success = 0;
                             }
                         }
                         if ($success) {
                             for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
                                 $position = Key($this->blobs[$prepared_query]);
                                 $blob_stream = $this->prepared_queries[$prepared_query - 1]["Values"][$position - 1];
                                 for ($value = ""; !MetabaseEndOfLOB($blob_stream);) {
                                     if (MetabaseReadLOB($blob_stream, $data, $this->lob_buffer_length) < 0) {
                                         $this->SetError("Do query", MetabaseLOBError($blob));
                                         $success = 0;
                                         break;
                                     }
                                     $value .= $data;
                                 }
                                 if ($success && !$descriptors[$position]->save($value)) {
                                     $this->SetOCIError("Do query", "Could not upload blob data", OCIError($statement));
                                     $success = 0;
                                 }
                             }
                         }
                     }
                     if ($this->auto_commit) {
                         if ($lobs) {
                             if ($success) {
                                 if (!OCICommit($this->connection)) {
                                     $this->SetOCIError("Do query", "Could not commit pending LOB updating transaction", OCIError());
                                     $success = 0;
                                 }
                             } else {
                                 if (!OCIRollback($this->connection)) {
                                     $this->SetOCIError("Do query", $this->Error() . " and then could not rollback LOB updating transaction", OCIError());
                                 }
                             }
                         }
                     } else {
                         $this->uncommitedqueries++;
                     }
                     if ($success) {
                         switch (OCIStatementType($statement)) {
                             case "SELECT":
                                 $result_value = intval($statement);
                                 $this->current_row[$result_value] = -1;
                                 if ($limit > 0) {
                                     $this->limits[$result_value] = array($first, $limit, 0);
                                 }
                                 $this->highest_fetched_row[$result_value] = -1;
                                 break;
                             default:
                                 $this->affected_rows = OCIRowCount($statement);
                                 OCIFreeCursor($statement);
                                 break;
                         }
                         $result = $statement;
                     }
                 } else {
                     $this->SetOCIError("Do query", "Could not execute query", OCIError($statement));
                 }
             }
         } else {
             $this->SetOCIError("Do query", "Could not parse query", OCIError($statement));
         }
     }
     for (Reset($descriptors), $descriptor = 0; $descriptor < count($descriptors); $descriptor++, Next($descriptors)) {
         @OCIFreeDesc($descriptors[Key($descriptors)]);
     }
     return $result;
 }
Example #10
0
 function execute_request($value_query, $value_config, $Param)
 {
     global $debug;
     //Constitution de la requete finale
     $requete = $value_query['code_sql'];
     if (!is_array($Param)) {
         eko("pb d'argument pour requete {$requete}");
     }
     while (list($key, $val) = each($Param)) {
         $searched_str = "\$" . $key;
         $requete = str_replace($searched_str, $val, $requete);
     }
     // echo $requete;
     // On place les colonnes à ramener dans un tableau $tab_cols
     if ($value_query['colonnes'] != '*' & $value_query['colonnes'] != '') {
         $tab_cols = split(",", $value_query['colonnes']);
     }
     switch ($value_config['type']) {
         case "MySQL":
             // Connexion au serveur Mysql & Execution de la requete
             // eko ( $value_config ) ;
             $conn = @mysql_connect($value_config['host'], $value_config['login'], $value_config['password']);
             if (!$conn) {
                 global $errs;
                 if ($errs) {
                     $errs->addErreur("La connexion au serveur MySQL \"" . $value_config['host'] . "\" avec l'utilisateur \"" . $value_config['login'] . "\" et le mot de passe \"*******\" a échoué.");
                 }
             }
             // eko ( "connexion : ".$value_config[login]."/".$value_config[password]."@". $value_config[host] ) ;
             $INDIC_SVC[0] = mysql_errno();
             $INDIC_SVC[1] = mysql_error();
             // pas de problème de connexion
             if (!$INDIC_SVC[0]) {
                 // execution de la raquete
                 if (!$this->forceBase) {
                     $result = @mysql_select_db($value_config['db']);
                 } else {
                     $result = @mysql_select_db($this->forceBase);
                 }
                 $result = @mysql_query($requete);
                 //echo "<h1>REQUETE : $requete</h1>";
                 $INDIC_SVC[0] = mysql_errno();
                 $INDIC_SVC[1] = mysql_error();
                 // pas de problème à l'execution de la requete
                 if (!$INDIC_SVC[0]) {
                     // Analyse du type de requete
                     if (DEBUGSQL and function_exists('eko')) {
                         eko($requete);
                     }
                     $qry_type = explode(" ", $requete);
                     switch (strtoupper($qry_type[0])) {
                         case "SELECT":
                             $nrows = mysql_num_rows($result);
                             if ($nrows) {
                                 // le nom des colonnes a ramener est *
                                 if (!isset($tab_cols)) {
                                     for ($i = 0; $i < mysql_num_fields($result); $i++) {
                                         $tab_cols[] = mysql_field_name($result, $i);
                                     }
                                 }
                                 // Maintenant On connait $tab_cols
                                 while ($record = mysql_fetch_array($result)) {
                                     // affectation dans les tableau de colonnes
                                     //jeton de debugage quand même colones
                                     unset($jeton);
                                     while (list($key, $val) = each($tab_cols)) {
                                         if (!isset($jeton[$val])) {
                                             $jeton[$val] = true;
                                         } else {
                                             $jeton[$val] = false;
                                         }
                                         if (isset(${$val})) {
                                             if ($jeton[$val]) {
                                                 ${$val} .= $record[$val] . "§";
                                                 //if ($debug) eko($val."-".$$val);
                                             }
                                         } else {
                                             ${$val} = $record[$val] . "§";
                                         }
                                     }
                                     reset($tab_cols);
                                 }
                                 //Construction des tableaux de colonnes
                                 unset($jeton);
                                 //print "********************* Tableau **********************<br>".affTab ( $tab_cols ) ;
                                 while (list($key, $val) = each($tab_cols)) {
                                     //print "/////////////////// Case ////////////////////<br>".affTab ( $jeton[$val] ) ;
                                     if (!isset($jeton[$val])) {
                                         $jeton[$val] = true;
                                     } else {
                                         $jeton[$val] = false;
                                     }
                                     if ($jeton[$val]) {
                                         // on retire le dernier |
                                         //print "<br>dollardollarval : ".$$val ;
                                         ${$val} = substr(${$val}, 0, strlen(${$val}) - 1);
                                         $resultats[$val] = explode("§", ${$val});
                                     }
                                     //if ($debug) eko($resultats[$val]);
                                 }
                             }
                             $INDIC_SVC[2] = $nrows;
                             break;
                         case "INSERT":
                             $INDIC_SVC[2] = mysql_affected_rows();
                             $INDIC_SVC[3] = mysql_insert_id();
                             break;
                         case "UPDATE":
                         case "DELETE":
                             $INDIC_SVC[2] = mysql_affected_rows();
                             break;
                     }
                 }
             }
             //mysql_close ( $conn ) ;
             break;
         case "MSSQL":
             // Connexion au serveur Mssql & Execution de la requete
             //print affTab ( $value_config ) ;
             //mssql_connect('galileo.ch-brignoles.fr','user_dim' ,'') || die ( 'hop' ) ;
             //mssql_connect("galileo","user_dim","") ||die ("Connexion impossible au serveur!");
             $conn = mssql_pconnect($value_config['host'], $value_config['login'], $value_config['password']);
             if (!$conn) {
                 global $errs;
                 if ($errs) {
                     $errs->addErreur("La connexion au serveur MsSQL \"" . $value_config['host'] . "\" avec l'utilisateur \"" . $value_config['login'] . "\" et le mot de passe \"*******\" a échoué.");
                 }
             }
             // eko ( "connexion : ".$value_config[login]."/".$value_config[password]."@". $value_config[host] ) ;
             //$INDIC_SVC[0] = mssql_get_last_message ( ) ;
             //$INDIC_SVC[1] = mssql_get_last_message ( ) ;
             // pas de problème de connexion
             if (!$INDIC_SVC[0]) {
                 // execution de la raquete
                 $result = mssql_select_db($value_config['db']);
                 $result = mssql_query($requete);
                 //echo "<h1>REQUETE : $requete</h1>";
                 //$INDIC_SVC[0] = mssql_get_last_message ( ) ;
                 //$INDIC_SVC[1] = mssql_get_last_message ( ) ;
                 // pas de problème à l'execution de la requete
                 if (!$INDIC_SVC[0]) {
                     // Analyse du type de requete
                     if (DEBUGSQL and function_exists('eko')) {
                         eko($requete);
                     }
                     $qry_type = explode(" ", $requete);
                     switch (strtoupper($qry_type[0])) {
                         case "SELECT":
                             $nrows = mssql_num_rows($result);
                             //eko ( "nombre de lignes : $nrows" ) ;
                             if ($nrows) {
                                 // le nom des colonnes a ramener est *
                                 if (!isset($tab_cols)) {
                                     for ($i = 0; $i < mssql_num_fields($result); $i++) {
                                         $tab_cols[] = mssql_field_name($result, $i);
                                     }
                                 }
                                 // Maintenant On connait $tab_cols
                                 while ($record = mssql_fetch_array($result)) {
                                     // affectation dans les tableau de colonnes
                                     //jeton de debugage quand même colones
                                     unset($jeton);
                                     while (list($key, $val) = each($tab_cols)) {
                                         if (!isset($jeton[$val])) {
                                             $jeton[$val] = true;
                                         } else {
                                             $jeton[$val] = false;
                                         }
                                         if (isset(${$val})) {
                                             if ($jeton[$val]) {
                                                 ${$val} .= $record[$val] . "§";
                                                 // eko ( $record[$val] ) ;
                                                 //if ($debug) eko($val."-".$$val);
                                             }
                                         } else {
                                             ${$val} = $record[$val] . "§";
                                         }
                                     }
                                     reset($tab_cols);
                                 }
                                 // Construction des tableaux de colonnes
                                 unset($jeton);
                                 while (list($key, $val) = each($tab_cols)) {
                                     if (!isset($jeton[$val])) {
                                         $jeton[$val] = true;
                                     } else {
                                         $jeton[$val] = false;
                                     }
                                     if ($jeton[$val]) {
                                         // on retire le dernier |
                                         //print "<br>dollardollarval : ".$$val ;
                                         ${$val} = substr(${$val}, 0, strlen(${$val}) - 1);
                                         $resultats[$val] = explode("§", ${$val});
                                     }
                                     //if ($debug) eko($resultats[$val]);
                                 }
                             }
                             $INDIC_SVC[2] = $nrows;
                             break;
                         case "INSERT":
                             //$INDIC_SVC[2] = mssql_affected_rows ( ) ;
                             //$INDIC_SVC[3] = mssql_insert_id ( ) ;
                             break;
                         case "UPDATE":
                         case "DELETE":
                             //$INDIC_SVC[2] = mssql_affected_rows ( ) ;
                             break;
                     }
                 }
             }
             mssql_close($conn);
             break;
         case "ORACLE":
             //echo "oracle";
             // Connexion
             // eko ($value_config);
             //      $conn = @OCILogon ( $value_config['login'], $value_config['password'], $value_config['db'] ) ;
             $conn = @oci_pconnect($value_config['login'], $value_config['password'], $value_config['db']);
             //global $conn ;
             $conn_error = ocierror();
             // Problème à la connexion
             if ($conn_error) {
                 $INDIC_SVC[0] = $conn_error['code'];
                 $INDIC_SVC[1] = $conn_error['message'];
                 // pas de problème de connexion
             } else {
                 // print $requete;
                 // execution de la raquete
                 $stmt = OCIParse($conn, $requete);
                 // print ( $requete ) ;
                 if (DEBUGSQL and function_exists('eko')) {
                     eko($requete);
                 }
                 OCIExecute($stmt);
                 $INDIC_SVC[0] = $conn_error['code'];
                 $INDIC_SVC[1] = $conn_error['message'];
                 // pas de problème à l'execution de la requete
                 if (!$INDIC_SVC[0]) {
                     // Analyse du type de requete
                     $qry_type = OCIStatementType($stmt);
                     switch ($qry_type) {
                         case "SELECT":
                             $nrows = OCIFetchStatement($stmt, $results);
                             // eko ( "<P>There are $nrows records containing your criteria. ($requete)</P>" ) ;
                             if ($nrows) {
                                 // le nom des colonnes a ramener n'a pas été spécifié ou est *
                                 if (!isset($tab_cols)) {
                                     $ncols = OCINumCols($stmt);
                                     for ($k = 1; $k <= $ncols; $k++) {
                                         $tab_cols[] = OCIColumnName($stmt, $k);
                                     }
                                 }
                                 for ($j = 0; $j < $nrows; $j++) {
                                     if (isset($tab_cols) and is_array($tab_cols)) {
                                         while (list($key, $val) = each($tab_cols)) {
                                             if (isset(${$val})) {
                                                 ${$val} .= $results[$val][$j] . "§";
                                             } else {
                                                 ${$val} = $results[$val][$j] . "§";
                                             }
                                         }
                                     }
                                     reset($tab_cols);
                                 }
                             }
                             //Construction des tableaux de colonnes
                             if (isset($tab_cols) and is_array($tab_cols)) {
                                 while (list($key, $val) = each($tab_cols)) {
                                     // on retire le dernier |
                                     ${$val} = substr(${$val}, 0, strlen(${$val}) - 1);
                                     $resultats[$val] = explode("§", ${$val});
                                 }
                             }
                             $INDIC_SVC[2] = $nrows;
                             break;
                         case "INSERT":
                             $nrows = OCIRowCount($stmt);
                             $INDIC_SVC[2] = $nrows;
                             break;
                         case "UPDATE":
                         case "DELETE":
                             $nrows = OCIRowCount($stmt);
                             $INDIC_SVC[2] = $nrows;
                             break;
                     }
                 }
             }
             oci_close($conn);
             break;
         case "LDAP":
             // Connexion au serveur LDAP
             $ds = @ldap_connect($value_config['host']);
             $bind = @ldap_bind($ds);
             if ($ds) {
                 // On eclate les instructions LDAP dans un tableau
                 $instructions_ldap = explode("##", $requete);
                 $chemin = $instructions_ldap[0];
                 $filtre = $instructions_ldap[1];
                 // Fin de gestion du code sql
                 // Execution de la requete
                 $sr = ldap_search($ds, $chemin, $filtre);
                 // le nom des colonnes a ramener n'a pas été spécifié ou est *
                 if (!isset($tab_cols)) {
                     $entry = ldap_first_entry($ds, $sr);
                     $attrs = ldap_get_attributes($ds, $entry);
                     for ($l = 0; $l < sizeof($attrs); $l++) {
                         $tab_cols[] = $attrs[$l];
                     }
                 }
                 $result = ldap_get_entries($ds, $sr);
                 for ($i = 0; $i < $result["count"]; $i++) {
                     // test des attributs multivalués
                     while (list($key, $val) = each($tab_cols)) {
                         for ($v = 0; $v < sizeof($result[$i][$val]); $v++) {
                             if ($result[$i][$val][$v] != "") {
                                 if ($v == 0) {
                                     $separateur = "";
                                 } else {
                                     $separateur = "##";
                                 }
                                 $valeur_brut = explode(",", $result[$i][$val][$v]);
                                 if ($valeur_brut[1]) {
                                     $valeur_pure = explode("cn=", $valeur_brut[0]);
                                 } else {
                                     $valeur_pure[1] = $result[$i][$val][$v];
                                 }
                                 ${$val} .= $separateur . $valeur_pure[1];
                             }
                         }
                         ${$val} .= ",";
                     }
                     reset($tab_cols);
                 }
                 // Construction des tableaux de colonnes
                 while (list($key, $val) = each($tab_cols)) {
                     // on retire la dernière virgule
                     ${$val} = substr(${$val}, 0, strlen(${$val}) - 1);
                     $resultats[$val] = explode(",", ${$val});
                 }
             }
             $INDIC_SVC[0] = ldap_errno($ds);
             $INDIC_SVC[1] = ldap_error($ds);
             $INDIC_SVC[2] = $result["count"];
             break;
     }
     $INDIC_SVC[15] = $requete;
     if (isset($Param['RIFIFI'])) {
         echo "indicsvc[0]:{$INDIC_SVC['0']}<br>indicsvc[1]:{$INDIC_SVC['1']}<br>indicsvc[2]:{$INDIC_SVC['2']}<br>indicsvc[3]:{$INDIC_SVC['3']}<br>indicsvc[15]:{$INDIC_SVC['15']}<br>\n";
     }
     $resultats['INDIC_SVC'] = $INDIC_SVC;
     return $resultats;
 }
 /** returns rownum of affected rows */
 function affected($stmt = FALSE)
 {
     if (!$stmt) {
         $stmt = $this->stmt;
     }
     return @OCIRowCount($stmt);
 }
 function countrows()
 {
     return OCIRowCount($this->statement);
 }
Example #13
0
 function query($query)
 {
     //去掉查询语句的前后空格
     $query = trim($query);
     $return_value = 0;
     //清空缓存..
     $this->flush();
     //记录此函数如何被调用,用于调试...
     $this->func_call = "\$db->query(\"{$query}\")";
     //跟踪最后查询语句,用于调试..
     $this->last_query = $query;
     //解析查询语句
     if (!($stmt = OCIParse($this->dbh, $query))) {
         $this->print_error();
     } elseif (!($this->result = OCIExecute($stmt))) {
         $this->print_error();
     }
     $this->num_queries++;
     //执行insert, delete, update, replace操作
     if (preg_match('/^(insert|delete|update|create)\\s+/i', $query)) {
         //获取操作所影响的记录行数
         $return_value = $this->rows_affected = OCIRowCount($stmt);
     } else {
         //获取字段信息
         if ($num_cols = @OCINumCols($stmt)) {
             for ($i = 1; $i <= $num_cols; $i++) {
                 $this->col_info[$i - 1]->name = OCIColumnName($stmt, $i);
                 $this->col_info[$i - 1]->type = OCIColumnType($stmt, $i);
                 $this->col_info[$i - 1]->size = OCIColumnSize($stmt, $i);
             }
         }
         //获取查询结果
         if ($this->num_rows = @OCIFetchStatement($stmt, $results)) {
             //将结果集转变成对象,因为oracle的返回结果比较奇怪:)
             foreach ($results as $col_title => $col_contents) {
                 $row_num = 0;
                 //循环所有的行
                 foreach ($col_contents as $col_content) {
                     $this->last_result[$row_num]->{$col_title} = $col_content;
                     $row_num++;
                 }
             }
         }
         //获取查询结果行数
         $return_value = $this->num_rows;
     }
     //是否显示所有的查询信息
     $this->debug_all ? $this->debug() : null;
     return $return_value;
 }
Example #14
0
function dbi_affected_rows($conn, $res)
{
    if (strcmp($GLOBALS['db_type'], 'mysql') == 0) {
        return mysql_affected_rows($conn);
    } elseif (strcmp($GLOBALS['db_type'], 'mysqli') == 0) {
        return $conn->affected_rows;
    } elseif (strcmp($GLOBALS['db_type'], 'mssql') == 0) {
        return mssql_rows_affected($conn);
    } elseif (strcmp($GLOBALS['db_type'], 'oracle') == 0) {
        return $GLOBALS['oracle_statement'] >= 0 ? OCIRowCount($GLOBALS['oracle_statement']) : -1;
    } elseif (strcmp($GLOBALS['db_type'], 'postgresql') == 0) {
        return pg_affected_rows($res);
    } elseif (strcmp($GLOBALS['db_type'], 'odbc') == 0) {
        return odbc_num_rows($res);
    } elseif (strcmp($GLOBALS['db_type'], 'ibm_db2') == 0) {
        return db2_num_rows($res);
    } elseif (strcmp($GLOBALS['db_type'], 'ibase') == 0) {
        return ibase_affected_rows($conn);
    } elseif (strcmp($GLOBALS['db_type'], 'sqlite') == 0) {
        return sqlite_changes($conn);
    } else {
        dbi_fatal_error('dbi_free_result (): ' . translate('db_type not defined.'));
    }
}
Example #15
0
 /**
  * Returns the number of rows affected
  *
  * @param resource $result
  * @param resource $connection
  * @return mixed MDB2 Error Object or the number of rows affected
  * @access private
  */
 function _affectedRows($connection, $result = null)
 {
     if (is_null($connection)) {
         $connection = $this->getConnection();
         if (PEAR::isError($connection)) {
             return $connection;
         }
     }
     return @OCIRowCount($result);
 }
Example #16
0
 function Affected_Rows()
 {
     return OCIRowCount($this->_stmt);
 }
Example #17
0
<?php 
require 'loginform.php';
if (isset($_POST['felhnev']) && isset($_POST['jelszo']) && isset($_POST['tipus'])) {
    $username = $_POST['felhnev'];
    $password = $_POST['jelszo'];
    $tipus = $_POST['tipus'];
    if ($tipus == 'szaki') {
        $query = "SELECT * FROM SZAKI WHERE FELHASZNALONEV = '" . $username . "' and JELSZO='" . $password . "'";
    } else {
        if ($tipus == 'felhasz') {
            $query = "SELECT * FROM FELHASZNALO WHERE FELHASZNALONEV = '" . $username . "' and JELSZO='" . $password . "'";
        }
    }
    $stid = oci_parse($conn, $query);
    oci_execute($stid);
    $tmpcount = OCIFetch($stid);
    if ($tmpcount == 1) {
        $count = OCIRowCount($stid);
        if ($count == 1) {
            $_SESSION['user'] = $username;
            header('Location: index.php');
        }
    } else {
        echo '<div align="center" class="alert alert-danger" style="width:300px;">Hibás jelszó vagy felhasználó név vagy rossz típus választás.<div>';
    }
}
?>

</div>
</body>
</html>
Example #18
0
 function query($query)
 {
     $return_value = 0;
     // Flush cached values..
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     $this->count(true, true);
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbname);
     }
     // Parses the query and returns a statement..
     if (!($stmt = OCIParse($this->dbh, $query))) {
         $error = OCIError($this->dbh);
         $this->register_error($error["message"]);
         $this->show_errors ? trigger_error($error["message"], E_USER_WARNING) : null;
         return false;
     } elseif (!($this->result = OCIExecute($stmt))) {
         $error = OCIError($stmt);
         $this->register_error($error["message"]);
         $this->show_errors ? trigger_error($error["message"], E_USER_WARNING) : null;
         return false;
     }
     // If query was an insert
     $is_insert = false;
     if (preg_match('/^(insert|delete|update|create) /i', $query)) {
         $is_insert = true;
         // num afected rows
         $return_value = $this->rows_affected = @OCIRowCount($stmt);
     } else {
         // Get column information
         if ($num_cols = @OCINumCols($stmt)) {
             // Fetch the column meta data
             for ($i = 1; $i <= $num_cols; $i++) {
                 $this->col_info[$i - 1]->name = @OCIColumnName($stmt, $i);
                 $this->col_info[$i - 1]->type = @OCIColumnType($stmt, $i);
                 $this->col_info[$i - 1]->size = @OCIColumnSize($stmt, $i);
             }
         }
         // If there are any results then get them
         if ($this->num_rows = @OCIFetchStatement($stmt, $results)) {
             // Convert results into object orientated results..
             // Due to Oracle strange return structure - loop through columns
             foreach ($results as $col_title => $col_contents) {
                 $row_num = 0;
                 // then - loop through rows
                 foreach ($col_contents as $col_content) {
                     $this->last_result[$row_num]->{$col_title} = $col_content;
                     $row_num++;
                 }
             }
         }
         // num result rows
         $return_value = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_value;
 }
Example #19
0
 /**
  * Determines the number of rows affected by a data maniuplation query
  *
  * 0 is returned for queries that don't manipulate data.
  *
  * @return int  the number of rows.  A DB_Error object on failure.
  */
 function affectedRows()
 {
     if ($this->last_stmt === false) {
         return $this->oci8RaiseError();
     }
     $result = @OCIRowCount($this->last_stmt);
     if ($result === false) {
         return $this->oci8RaiseError($this->last_stmt);
     }
     return $result;
 }
Example #20
0
 /**
  * Execute a query
  * @param string $query the SQL query
  * @return mixed result identifier if query executed, else MDB2_error
  * @access private
  **/
 function _doQuery($query, $ismanip = null, $prepared_query = 0)
 {
     $lobs = 0;
     $success = MDB2_OK;
     $result = 0;
     $descriptors = array();
     if ($prepared_query) {
         $columns = '';
         $variables = '';
         for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
             $clob_stream = key($this->clobs[$prepared_query]);
             $descriptors[$clob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB);
             if (!is_object($descriptors[$clob_stream])) {
                 $success = $this->raiseError(MDB2_ERROR, null, null, 'Could not create descriptor for clob parameter');
                 break;
             }
             $parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter;
             $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['fields'][$parameter - 1];
             $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':clob' . $parameter;
             ++$lobs;
         }
         if (!MDB2::isError($success)) {
             for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
                 $blob_stream = key($this->blobs[$prepared_query]);
                 $descriptors[$blob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB);
                 if (!is_object($descriptors[$blob_stream])) {
                     $success = $this->raiseError(MDB2_ERROR, null, null, 'Could not create descriptor for blob parameter');
                     break;
                 }
                 $parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter;
                 $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['fields'][$parameter - 1];
                 $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':blob' . $parameter;
                 ++$lobs;
             }
             $query .= $columns . $variables;
         }
     }
     if (!MDB2::isError($success)) {
         if ($statement = @OCIParse($this->connection, $query)) {
             if ($lobs) {
                 for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
                     $clob_stream = key($this->clobs[$prepared_query]);
                     $parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter;
                     if (!OCIBindByName($statement, ':clob' . $parameter, $descriptors[$clob_stream], -1, OCI_B_CLOB)) {
                         $success = $this->raiseError();
                         break;
                     }
                 }
                 if (!MDB2::isError($success)) {
                     for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
                         $blob_stream = key($this->blobs[$prepared_query]);
                         $parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter;
                         if (!OCIBindByName($statement, ':blob' . $parameter, $descriptors[$blob_stream], -1, OCI_B_BLOB)) {
                             $success = $this->raiseError();
                             break;
                         }
                     }
                 }
             }
             if (!MDB2::isError($success)) {
                 $mode = $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT;
                 $result = @OCIExecute($statement, $mode);
                 if ($result) {
                     if ($lobs) {
                         for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
                             $clob_stream = key($this->clobs[$prepared_query]);
                             for ($value = ''; !$this->datatype->endOfLOB($clob_stream);) {
                                 if ($this->datatype->readLOB($clob_stream, $data, $this->options['lob_buffer_length']) < 0) {
                                     $success = $this->raiseError();
                                     break;
                                 }
                                 $value .= $data;
                             }
                             if (!MDB2::isError($success) && !$descriptors[$clob_stream]->save($value)) {
                                 $success = $this->raiseError();
                             }
                         }
                         if (!MDB2::isError($success)) {
                             for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
                                 $blob_stream = key($this->blobs[$prepared_query]);
                                 for ($value = ''; !$this->datatype->endOfLOB($blob_stream);) {
                                     if ($this->datatype->readLOB($blob_stream, $data, $this->options['lob_buffer_length']) < 0) {
                                         $success = $this->raiseError();
                                         break;
                                     }
                                     $value .= $data;
                                 }
                                 if (!MDB2::isError($success) && !$descriptors[$blob_stream]->save($value)) {
                                     $success = $this->raiseError();
                                 }
                             }
                         }
                     }
                     if ($this->auto_commit) {
                         if ($lobs) {
                             if (MDB2::isError($success)) {
                                 if (!OCIRollback($this->connection)) {
                                     $success = $this->raiseError();
                                 }
                             } else {
                                 if (!OCICommit($this->connection)) {
                                     $success = $this->raiseError();
                                 }
                             }
                         }
                     } else {
                         ++$this->uncommitedqueries;
                     }
                     if (!MDB2::isError($success)) {
                         if (is_null($ismanip)) {
                             $ismanip = MDB2::isManip($query);
                         }
                         if ($ismanip) {
                             $this->affected_rows = @OCIRowCount($statement);
                             @OCIFreeCursor($statement);
                         }
                         $result = $statement;
                     }
                 } else {
                     return $this->raiseError($statement);
                 }
             }
         } else {
             return $this->raiseError();
         }
     }
     for (reset($descriptors), $descriptor = 0; $descriptor < count($descriptors); $descriptor++, next($descriptors)) {
         @$descriptors[key($descriptors)]->free();
     }
     if (MDB2::isError($success)) {
         return $success;
     }
     return $result;
 }
	function _affectedrows()
	{
		if (is_resource($this->_stmt)) return @OCIRowCount($this->_stmt);
		return 0;
	}
Example #22
0
 function sql_affectedrows($query_id = 0)
 {
     if (!$query_id) {
         $query_id = $this->query_result;
     }
     if ($query_id) {
         $result = @OCIRowCount($query_id);
         return $result;
     } else {
         return false;
     }
 }