Example #1
0
/**
 * PHP Template.
 */
function updateSF($tableName, $rowID, $sfID)
{
    $odbc = odbcConnect();
    $stmt = odbc_prepare($odbc, "INSERT into SalesForceUpdateQueue (creationDate, mysqlTableName, mysqlRowID, salesForceID) VALUES(CURRENT_TIMESTAMP(), ?, ?, ?)");
    $rs = odbc_execute($stmt, array($tableName, $rowID, $sfID));
    odbc_close($odbc);
}
Example #2
0
 protected function _exec($sql, $params = array())
 {
     $this->_stmt = odbc_prepare($this->_con, $sql);
     if ($this->_stmt === false) {
         $this->raiseError($this->_stmt, $params);
     }
     $res = odbc_execute($this->_stmt, $params);
     if ($res === false) {
         $this->raiseError($sql, $params);
     }
     return $res;
 }
Example #3
0
 /**
  * Prepare a query, execute it and return an ODBC result identifier
  * @param string $query
  * @param array $params
  * @return bool|resource
  * @throws Exception
  */
 protected function executePreparedStatement($query, $params)
 {
     $res = odbc_prepare($this->_lnk, $query);
     if (!$res) {
         $error = odbc_errormsg($this->_lnk);
         $this->log('Prepare failed: ' . $error);
         throw new Exception('Preparing query failed ' . $error, self::PREPARE_FAILED);
     }
     $res = odbc_execute($res, $params);
     if (!$res) {
         $error = odbc_errormsg($this->_lnk);
         $this->log('Prepared query execution failed: ' . $error);
         throw new Exception('Executing prepared query failed ' . $error, self::QUERY_FAILED);
     }
     return $res;
 }
Example #4
0
 /**
  * Executes the supplied SQL statement and returns
  * the result of the call.
  * 
  * @access  public
  *  
  * @param   string  SQL to execute
  */
 function exec()
 {
     if (func_num_args() > 1) {
         $args = func_get_args();
         $sql = $args[0];
         unset($args[0]);
         // remove the sql
         $args = array_values($args);
         // and reset the array index
     } else {
         $sql = func_get_arg(0);
     }
     $this->ensureConnection();
     if (isset($args)) {
         $result = odbc_prepare($this->connection, $sql);
         if (!odbc_execute($result, $args)) {
             throw new Exception(odbc_errormsg($this->connection));
         }
         return odbc_num_rows($result);
     } else {
         return odbc_exec($this->connection, $sql);
     }
 }
 /**
  * Internal function to call native ODBC prepare/execute functions.
  */
 protected function _execute($sql, $params, $fetchmode, $isupdate)
 {
     // Set any params passed directly
     if ($params) {
         for ($i = 0, $cnt = count($params); $i < $cnt; $i++) {
             $this->set($i + 1, $params[$i]);
         }
     }
     // Trim surrounding quotes added from default set methods.
     // Exception: for LOB-based parameters, odbc_execute() will
     // accept a filename surrounded by single-quotes.
     foreach ($this->boundInVars as $idx => $var) {
         if ($var instanceof Lob) {
             $file = $isupdate ? $var->getInputFile() : $var->getOutputFile();
             $this->boundInVars[$idx] = "'{$file}'";
         } else {
             if (is_string($var)) {
                 $this->boundInVars[$idx] = trim($var, "\"\\'");
             }
         }
     }
     if ($this->resultSet) {
         $this->resultSet->close();
         $this->resultSet = null;
     }
     $this->updateCount = null;
     $stmt = @odbc_prepare($this->conn->getResource(), $sql);
     if ($stmt === FALSE) {
         throw new SQLException('Could not prepare query', $this->conn->nativeError(), $sql);
     }
     $ret = @odbc_execute($stmt, $this->boundInVars);
     if ($ret === FALSE) {
         @odbc_free_result($stmt);
         throw new SQLException('Could not execute query', $this->conn->nativeError(), $sql);
     }
     return $this->conn->createResultSet(new ODBCResultResource($stmt), $fetchmode);
 }
Example #6
0
 function get_report(client $client, $table_name, $show, $rownum)
 {
     if ($table_name == null) {
         return "Bad table name.";
     }
     //TODO check table_name is one word
     //compile query
     $colnames = odbc_exec($client->get_connection(), "SELECT column_name, data_type, data_length FROM ALL_TAB_COLUMNS WHERE table_name = '" . strtoupper($table_name) . "';");
     if ($colnames === false) {
         return "Unable to get table fields.";
     }
     $query = "SELECT ";
     $i = 0;
     while (odbc_fetch_row($colnames)) {
         if (isset($show) && isset($show[$i]) && $show[$i] == true) {
             if ($query != "SELECT ") {
                 $query .= ", ";
             }
             $query .= odbc_result($colnames, 1);
         }
         $i += 1;
     }
     $query .= " FROM " . $table_name . " WHERE rownum <= ?;";
     //prepare statement
     $statement = odbc_prepare($client->get_connection(), $query);
     if ($statement === false) {
         return $query . "\n\n" . get_odbc_error();
     }
     $items = array();
     $items[] = (int) $rownum;
     $result = odbc_execute($statement, $items);
     if ($result === false) {
         return $query . "\n\n" . get_odbc_error();
     }
     return $statement;
 }
Example #7
0
function deleteServer($id)
{
    $odbc = odbcConnect();
    $stmt = odbc_prepare($odbc, "DELETE FROM servers WHERE id = ?");
    $rs = odbc_execute($stmt, array($id));
    odbc_close($odbc);
    return $rs;
}
Example #8
0
 public function prepare($query, $logComponent)
 {
     Timer::start($logComponent . '::odbc_prepare');
     $result = @odbc_prepare($this->con, $query);
     Timer::stop($logComponent . '::odbc_prepare');
     if (false === $result) {
         $errornr = odbc_error($this->con);
         $err = odbc_errormsg($this->con);
         //echo $err.$errornr;die;
         switch ($errornr) {
             case 37000:
                 Logger::warn($logComponent . "::odbc_prepare failed: query length = " . strlen($query) . "\n" . $err);
                 break;
             case '08S01':
                 Logger::warn($logComponent . "::odbc_prepare: lost connection to server going into loop" . $err);
                 Logger::warn("Waiting at: ***********\n" . substr($query, 0, self::cutstring));
                 Logger::warn("Previous was:**********\n" . $this->previous);
                 do {
                     Logger::warn('Currently looping last odbc_prepare, waiting ' . self::wait . ' and retrying');
                     sleep(self::wait);
                     $this->connect(true);
                     $result = @odbc_prepare($this->con, $query);
                     $errornr = odbc_error($this->con);
                 } while (false === $result && $errornr == '08S01');
                 break;
             case 40001:
             case 'SR172':
                 Logger::warn($logComponent . "::odbc_prepare: Transaction deadlocked, going into loop" . $err);
                 Logger::warn("Waiting at: ***********\n" . substr($query, 0, self::cutstring));
                 Logger::warn("Previous was:**********\n" . $this->previous);
                 do {
                     Logger::warn('Currently looping last odbc_prepare, waiting ' . self::wait . ' and retrying');
                     sleep(self::wait);
                     $this->connect(true);
                     $result = @odbc_prepare($this->con, $query);
                     $errornr = odbc_error($this->con);
                 } while (false === $result && $errornr == 'SR172');
                 break;
             default:
                 Logger::warn($logComponent . "::odbc_prepare failed: \n" . $query . "\nnumber: " . $errornr . "\nerror: " . $err);
         }
     } else {
         Logger::debug($logComponent . ":: successfully prepared  ({$query}): ");
     }
     $this->setPrevious($query);
     return $result;
 }
Example #9
0
}
if (!odbc_autocommit($conn_id, FALSE)) {
    exit("Failed to turn off AutoCommit mode\n");
}
if (!odbc_exec($conn_id, "DROP TABLE tsttbl IF EXISTS")) {
    exit("DROP command failed\n");
}
if (!odbc_exec($conn_id, "CREATE TABLE tsttbl(\n    id BIGINT generated BY DEFAULT AS IDENTITY,\n    vc VARCHAR(20),\n    entrytime TIMESTAMP DEFAULT current_timestamp NOT NULL\n)")) {
    exit("CREATE TABLE command failed\n");
}
# First do a non-parameterized insert
if (!odbc_exec($conn_id, "INSERT INTO tsttbl(id, vc) VALUES(1, 'one')")) {
    exit("Insertion of first row failed\n");
}
# Now parameterized inserts
$stmt = odbc_prepare($conn_id, "INSERT INTO tsttbl(id, vc) VALUES(?, ?)");
if (!$stmt) {
    exit("Preparation of INSERT statement failed \n");
}
# With (default) debug mode, the following statements will generate
# annoying "cursor updatability" warnings.
$rv = odbc_execute($stmt, array(2, 'two'));
if ($rv != 1) {
    exit("2nd Insertion failed with  value {$rv}\n");
}
$rv = odbc_execute($stmt, array(3, 'three'));
if ($rv != 1) {
    exit("3rd Insertion failed with  value {$rv}\n");
}
$rv = odbc_execute($stmt, array(4, 'four'));
if ($rv != 1) {
Example #10
0
 function _query($sql, $inputarr = false)
 {
     global $php_errormsg;
     $php_errormsg = '';
     $this->_error = '';
     if ($inputarr) {
         if (is_resource($sql)) {
             $stmtid = $sql;
         } else {
             $stmtid = odbc_prepare($this->_connectionID, $sql);
         }
         if ($stmtid == false) {
             $this->_errorMsg = $php_errormsg;
             return false;
         }
         //print_r($inputarr);
         if (!odbc_execute($stmtid, $inputarr)) {
             @odbc_free_result($stmtid);
             return false;
         }
     } else {
         $stmtid = odbc_exec($this->_connectionID, $sql);
     }
     if ($stmtid) {
         odbc_binmode($stmtid, $this->binmode);
         odbc_longreadlen($stmtid, $this->maxblobsize);
     }
     $this->_errorMsg = $php_errormsg;
     return $stmtid;
 }
Example #11
0
 /**
  * Compile Bindings
  *
  * @param	string	$sql	SQL statement
  * @param	array	$binds	An array of values to bind
  * @return	string
  */
 public function compile_binds($sql, $binds)
 {
     if (empty($binds) or empty($this->bind_marker) or strpos($sql, $this->bind_marker) === FALSE) {
         return $sql;
     } elseif (!is_array($binds)) {
         $binds = array($binds);
         $bind_count = 1;
     } else {
         // Make sure we're using numeric keys
         $binds = array_values($binds);
         $bind_count = count($binds);
     }
     // We'll need the marker length later
     $ml = strlen($this->bind_marker);
     // Make sure not to replace a chunk inside a string that happens to match the bind marker
     if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches)) {
         $c = preg_match_all('/' . preg_quote($this->bind_marker, '/') . '/i', str_replace($matches[0], str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), $sql, $c), $matches, PREG_OFFSET_CAPTURE);
         // Bind values' count must match the count of markers in the query
         if ($bind_count !== $c) {
             return $sql;
         }
     } elseif (($c = preg_match_all('/' . preg_quote($this->bind_marker, '/') . '/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) {
         return $sql;
     }
     if ($this->bind_marker !== '?') {
         do {
             $c--;
             $sql = substr_replace($sql, '?', $matches[0][$c][1], $ml);
         } while ($c !== 0);
     }
     if (FALSE !== ($this->odbc_result = odbc_prepare($this->conn_id, $sql))) {
         $this->binds = array_values($binds);
     }
     return $sql;
 }
Example #12
0
 /**
  * Sets up a prepared statement
  * 
  * @internal
  * 
  * @param  fDatabase $database            The database object this result set was created from
  * @param  string    $query               MSSQL only: the character set to transcode from since MSSQL doesn't do UTF-8
  * @param  array     $placeholders        The data type placeholders
  * @param  string    $untranslated_query  If the SQL was translated - only relevant for Oracle
  * @return fResult
  */
 public function __construct($database, $query, $placeholders, $untranslated_sql)
 {
     if (!$database instanceof fDatabase) {
         throw new fProgrammerException('The database object provided does not appear to be a descendant of fDatabase');
     }
     $this->database = $database;
     $this->placeholders = $placeholders;
     $this->sql = vsprintf($query, $placeholders);
     $this->untranslated_sql = $untranslated_sql;
     $extension = $this->database->getExtension();
     switch ($extension) {
         // These database extensions don't have prepared statements
         case 'mssql':
         case 'mysql':
         case 'sqlite':
             break;
         case 'oci8':
             $named_placeholders = array();
             for ($i = 1; $i <= sizeof($placeholders); $i++) {
                 $named_placeholders[] = ':p' . $i;
             }
             $query = vsprintf($query, $named_placeholders);
             break;
         case 'ibm_db2':
         case 'mysqli':
         case 'odbc':
         case 'pdo':
         case 'sqlsrv':
             $question_marks = array();
             if (sizeof($placeholders)) {
                 $question_marks = array_fill(0, sizeof($placeholders), '?');
             }
             $query = vsprintf($query, $question_marks);
             break;
         case 'pgsql':
             $dollar_placeholders = array();
             for ($i = 1; $i <= sizeof($placeholders); $i++) {
                 $dollar_placeholders[] = '$' . $i;
             }
             $query = vsprintf($query, $dollar_placeholders);
             break;
     }
     $connection = $this->database->getConnection();
     $old_level = error_reporting(error_reporting() & ~E_WARNING);
     switch ($extension) {
         // These database extensions don't have prepared statements
         case 'mssql':
         case 'mysql':
         case 'sqlite':
             $statement = $query;
             break;
         case 'ibm_db2':
             $statement = db2_prepare($connection, $query, array('cursor' => DB2_FORWARD_ONLY));
             break;
         case 'mysqli':
             $statement = mysqli_prepare($connection, $query);
             break;
         case 'oci8':
             $statement = oci_parse($connection, $query);
             break;
         case 'odbc':
             $statement = odbc_prepare($connection, $query);
             break;
         case 'pdo':
             $statement = $connection->prepare($query);
             break;
         case 'pgsql':
             static $statement_number = 0;
             $statement_number++;
             $this->identifier = 'fstmt' . $statement_number;
             $statement = pg_prepare($connection, $this->identifier, $query);
             break;
         case 'sqlsrv':
             $params = array();
             for ($i = 0; $i < sizeof($placeholders); $i++) {
                 $this->bound_params[$i] = NULL;
                 $params[$i] =& $this->bound_params[$i];
             }
             $statement = sqlsrv_prepare($connection, $query, $params);
             break;
     }
     error_reporting($old_level);
     if (!$statement) {
         switch ($extension) {
             case 'ibm_db2':
                 $message = db2_stmt_errormsg($statement);
                 break;
             case 'mysqli':
                 $message = mysqli_error($connection);
                 break;
             case 'oci8':
                 $error_info = oci_error($statement);
                 $message = $error_info['message'];
                 break;
             case 'odbc':
                 $message = odbc_errormsg($connection);
                 break;
             case 'pgsql':
                 $message = pg_last_error($connection);
                 break;
             case 'sqlsrv':
                 $error_info = sqlsrv_errors(SQLSRV_ERR_ALL);
                 $message = $error_info[0]['message'];
                 break;
             case 'pdo':
                 $error_info = $connection->errorInfo();
                 $message = $error_info[2];
                 break;
         }
         $db_type_map = array('db2' => 'DB2', 'mssql' => 'MSSQL', 'mysql' => 'MySQL', 'oracle' => 'Oracle', 'postgresql' => 'PostgreSQL', 'sqlite' => 'SQLite');
         throw new fSQLException('%1$s error (%2$s) in %3$s', $db_type_map[$this->database->getType()], $message, $this->sql);
     }
     $this->statement = $statement;
 }
 function _query($sql, $inputarr = false)
 {
     global $php_errormsg;
     if (isset($php_errormsg)) {
         $php_errormsg = '';
     }
     $this->_error = '';
     if ($inputarr) {
         if (is_array($sql)) {
             $stmtid = $sql[1];
         } else {
             $stmtid = odbc_prepare($this->_connectionID, $sql);
             if ($stmtid == false) {
                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
                 return false;
             }
         }
         if (!odbc_execute($stmtid, $inputarr)) {
             //@odbc_free_result($stmtid);
             if ($this->_haserrorfunctions) {
                 $this->_errorMsg = odbc_errormsg();
                 $this->_errorCode = odbc_error();
             }
             if ($this->_errorCode == '00000') {
                 // MS SQL Server sometimes returns this in combination with the FreeTDS
                 $this->_errorMsg = '';
                 // driver and UnixODBC under Linux. This fixes the bogus "error"
                 $this->_errorCode = 0;
                 // <*****@*****.**>
                 return true;
             }
             return false;
         }
     } else {
         if (is_array($sql)) {
             $stmtid = $sql[1];
             if (!odbc_execute($stmtid)) {
                 //@odbc_free_result($stmtid);
                 if ($this->_haserrorfunctions) {
                     $this->_errorMsg = odbc_errormsg();
                     $this->_errorCode = odbc_error();
                 }
                 if ($this->_errorCode == '00000') {
                     // MS SQL Server sometimes returns this in combination with the FreeTDS
                     $this->_errorMsg = '';
                     // driver and UnixODBC under Linux. This fixes the bogus "error"
                     $this->_errorCode = 0;
                     // <*****@*****.**>
                     return true;
                 }
                 return false;
             }
         } else {
             $stmtid = odbc_exec($this->_connectionID, $sql);
         }
     }
     $this->_lastAffectedRows = 0;
     if ($stmtid) {
         if (@odbc_num_fields($stmtid) == 0) {
             $this->_lastAffectedRows = odbc_num_rows($stmtid);
             $stmtid = true;
         } else {
             $this->_lastAffectedRows = 0;
             odbc_binmode($stmtid, $this->binmode);
             odbc_longreadlen($stmtid, $this->maxblobsize);
         }
         if ($this->_haserrorfunctions) {
             $this->_errorMsg = '';
             $this->_errorCode = 0;
         } else {
             $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
         }
     } else {
         if ($this->_haserrorfunctions) {
             $this->_errorMsg = odbc_errormsg();
             $this->_errorCode = odbc_error();
         } else {
             $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
         }
     }
     return $stmtid;
 }
Example #14
0
 /**
  * Execute an sql query
  */
 public function query($query, array $params = null)
 {
     # If the next query should be cached then run the cache function instead
     if ($this->cacheNext) {
         $this->cacheNext = false;
         return $this->cache($query, $params);
     }
     # Ensure we have a connection to run this query on
     $this->connect();
     $this->query = $query;
     $this->params = null;
     $this->preparedQuery = false;
     if (is_array($params)) {
         $this->params = $params;
     }
     $this->quoteChars($query);
     $this->functions($query);
     $this->limit($query);
     $this->tableNames($query);
     $this->namedParams($query, $params);
     $this->paramArrays($query, $params);
     $this->convertNulls($params);
     $preparedQuery = $this->prepareQuery($query, $params);
     $this->preparedQuery = $preparedQuery;
     if ($this->output) {
         if ($this->htmlMode) {
             echo "<pre>";
         }
         echo $preparedQuery;
         if ($this->htmlMode) {
             echo "<hr>";
         } else {
             echo "\n";
         }
     }
     switch ($this->mode) {
         case "mysql":
             if (!($result = $this->server->query($preparedQuery))) {
                 $this->error();
             }
             break;
         case "postgres":
         case "redshift":
             $tmpQuery = $query;
             $query = "";
             $noParams = false;
             if ($this->mode == "redshift" && count($params) > 32767) {
                 $noParams = true;
             }
             $i = 1;
             reset($params);
             while ($pos = strpos($tmpQuery, "?")) {
                 if ($noParams) {
                     $query .= substr($tmpQuery, 0, $pos) . "'" . pg_escape_string(current($params)) . "'";
                     next($params);
                 } else {
                     $query .= substr($tmpQuery, 0, $pos) . "\$" . $i++;
                 }
                 $tmpQuery = substr($tmpQuery, $pos + 1);
             }
             $query .= $tmpQuery;
             $params = Helper::toArray($params);
             if (!($result = pg_query_params($this->server, $query, $params))) {
                 $this->error();
             }
             break;
         case "odbc":
             if (!($result = odbc_prepare($this->server, $query))) {
                 $this->error();
             }
             $params = Helper::toArray($params);
             if (!odbc_execute($result, $params)) {
                 $this->error();
             }
             break;
         case "sqlite":
             if (!is_array($params)) {
                 if (!($result = $this->server->query($preparedQuery))) {
                     $this->error();
                 }
                 # If we have some parameters then we must convert them to the sqlite format
             } else {
                 $newQuery = "";
                 foreach ($params as $key => $val) {
                     $pos = strpos($query, "?");
                     $newQuery .= substr($query, 0, $pos);
                     $query = substr($query, $pos + 1);
                     $newQuery .= ":var" . $key;
                 }
                 $newQuery .= $query;
                 if (!($result = $this->server->prepare($newQuery))) {
                     $this->error();
                 }
                 foreach ($params as $key => $val) {
                     switch (gettype($val)) {
                         case "boolean":
                         case "integer":
                             $type = SQLITE3_INTEGER;
                             break;
                         case "double":
                             $type = SQLITE3_FLOAT;
                             break;
                         case "NULL":
                             if ($this->allowNulls) {
                                 $type = SQLITE3_NULL;
                             } else {
                                 $type = SQLITE3_TEXT;
                                 $val = "";
                             }
                             break;
                         default:
                             $type = SQLITE3_TEXT;
                     }
                     $result->bindValue(":var" . $key, $val, $type);
                 }
                 if (!($result = $result->execute())) {
                     $this->error();
                 }
             }
             break;
         case "mssql":
             if (!($result = mssql_query($preparedQuery, $this->server))) {
                 $this->error();
             }
             break;
     }
     if (!$result) {
         $this->error();
     }
     return new Result($result, $this->mode);
 }
Example #15
0
 public function fetch($sql, $bind, callable $callback)
 {
     $stmt = odbc_prepare($this->connection, $sql);
     odbc_execute($stmt, $this->repairBinding($bind));
     while ($row = odbc_fetch_array($stmt)) {
         $callback($row);
     }
     odbc_free_result($stmt);
 }
Example #16
0
/*---------------------*/
/*Atualizar Categoria*/
if (isset($_POST['idAtCat']) and $_POST['idAtCat'] != null) {
    $idAtCat = $_POST['idAtCat'];
    $nomeAtCat = $_POST['nomeAtCat'];
    $descAtCat = $_POST['descAtCat'];
    if (odbc_exec($connect, "UPDATE Categoria set nomeCategoria='" . $nomeAtCat . "', descCategoria='" . $descAtCat . "' WHERE idCategoria = " . $idAtCat)) {
        echo "<script>alert('Categoria atualizada com sucesso')</script>";
    }
}
/*--------------------*/
/*Atualizar Produto*/
if (isset($_POST['nomeAtProd']) and $_POST['idAtProd'] != null) {
    $idAtProd = $_POST['idAtProd'];
    $nomeAtProduto = $_POST['nomeAtProd'];
    $precoAtProduto = (double) $_POST['precoAtProd'];
    $descontoAtProduto = (double) $_POST['descontoAtProd'];
    $descricaoAtProduto = $_POST['descAtProd'];
    $statusAtProduto = (bool) $_POST['statusAtProduto'];
    $estoqueMinAtProduto = $_POST['estoqueMinAtProd'];
    if (substr($_FILES['imagemAtProd']['type'], 0, 5) == 'image' && $_FILES['imagemAtProd']['error'] == 0 && $_FILES['imagemAtProd']['size'] > 0) {
        $file = fopen($_FILES['imagemAtProd']['tmp_name'], 'rb');
        $fileAtParaDB = fread($file, filesize($_FILES['imagemAtProd']['tmp_name']));
        fclose($file);
    }
    $updateProduto = odbc_prepare($connect, "UPDATE Produto SET nomeProduto = ? ,precProduto = ?,descontoPromocao = ?,descProduto = ?,ativoProduto = ?,qtdMinEstoque = ?,imagem  = ? WHERE idProduto = ? ");
    if (odbc_execute($updateProduto, array($nomeAtProduto, $precoAtProduto, $descontoAtProduto, $descricaoAtProduto, $statusAtProduto, $estoqueMinAtProduto, $fileAtParaDB, $idAtProd))) {
        echo "<script>alert('Produto atualizado com sucesso')</script>";
    }
}
/*---------------------*/
Example #17
0
function deleteOrgAccount($id)
{
    $account = findOrgAccountById($id);
    if ($account['sfdc'] != "") {
        updateSF('org_members', $account['id'], $account['sfdc']);
    }
    $odbc = odbcConnect();
    $stmt = odbc_prepare($odbc, "DELETE FROM org_members WHERE id = ?");
    $rs = odbc_execute($stmt, array($id));
    odbc_close($odbc);
    return $rs;
}
 /**
  * Prepares SQL query as a statement and executes it with bind parameters
  *
  * @param string $sql        Given SQL query
  * @param array  $parameters Parameters to bind (optional in case you don't have placeholders in your query)
  *
  * @return bool
  * @throws VerticaQueryException
  * @author Sergii Katrych <*****@*****.**>
  */
 protected function prepareAndExecute($sql, array $parameters = array())
 {
     $stmt = odbc_prepare($this->getConnection(), $sql);
     if (false === $stmt) {
         throw new VerticaQueryException(odbc_errormsg($this->getConnection()), odbc_error($this->getConnection()));
     }
     // @TODO: validate and quote $parameters values
     $result = odbc_execute($stmt, $parameters);
     if (false === $result) {
         return false;
     }
     return odbc_num_rows($stmt);
 }
 function deleteFromODBC($sql, $params)
 {
     $results = odbc_prepare($this->conn, $sql);
     if ($results === false) {
         // throw new ErrorException(odbc_errormsg());
         return false;
     }
     if (odbc_execute($results, $params) === false) {
         return false;
         //throw new ErrorException(odbc_errormsg());
     }
     return $results;
 }
Example #20
0
 /**
  * Execute a query command in RDBMS
  *
  * @param string $query Query command to execute
  * @param array $params Array of parameters in query (default = null)
  * @return object | false
  */
 public function query($query, $params = null)
 {
     $resultSet = null;
     if (is_null($params)) {
         if ($resultSet = @odbc_exec($this->_connection, $query)) {
             return $resultSet;
         } else {
             $this->_errorCode = odbc_error($this->_connection) . '-' . odbc_errormsg($this->_connection);
             return false;
         }
     } else {
         if ($prepared_stmt = @odbc_prepare($this->_connection, $query)) {
             $resultSet = @odbc_execute($prepared_stmt, $params);
             if ($resultSet) {
                 return $prepared_stmt;
             } else {
                 $this->_errorCode = odbc_error($this->_connection) . '-' . odbc_errormsg($this->_connection);
                 return false;
             }
         } else {
             $this->_errorCode = odbc_error($this->_connection) . '-' . odbc_errormsg($this->_connection);
             return false;
         }
     }
 }
<head>
<meta charset="utf-8">
<title>Manage Action</title>
</head>

<body>
<?php 
if (isset($_FILES["paper_file"]) && $_FILES["paper_file"]["error"] > 0) {
    echo "Error: " . $_FILES["paper_ file"]["error"] . "<br />";
} elseif (isset($_FILES["paper_file"])) {
    move_uploaded_file($_FILES["paper_file"]["tmp_name"], "../uploads/UploadImages/" . $_FILES["paper_file"]["name"]);
    //Save the file as the supplied name
}
// create connection
$conn = odbc_connect('VEDB01access1', '', '');
if (!$conn) {
    exit("Connection Failed: " . $conn);
}
// create SQL statement
$sql = "INSERT INTO Employees([FirstName],[LastName],[Title])\n        VALUES('" . $_POST['paper_author'] . "','" . $_FILES["paper_file"]["name"] . "','" . $_POST['paper_title'] . "')";
// prepare SQL statement
$sql_result = odbc_prepare($conn, $sql);
// execute SQL statement and get results
odbc_execute($sql_result);
// free resources
odbc_free_result($sql_result);
?>

</body>
</html>
Example #22
0
 function DoQuery($query, $first = 0, $limit = 0, $prepared_query = 0)
 {
     if ($prepared_query && isset($this->query_parameters[$prepared_query]) && count($this->query_parameters[$prepared_query])) {
         if ($result = @odbc_prepare($this->connection, $query)) {
             if (!@odbc_execute($result, $this->query_parameters[$prepared_query])) {
                 $this->SetODBCError("Do query", "Could not execute a ODBC database prepared query \"{$query}\"", $php_errormsg);
                 odbc_free_result($result);
                 return 0;
             }
         } else {
             $this->SetODBCError("Do query", "Could not execute a ODBC database prepared query \"{$query}\"", $php_errormsg);
             return 0;
         }
     } else {
         $result = @odbc_exec($this->connection, $query);
     }
     if ($result) {
         $this->current_row[$result] = -1;
         if (substr(strtolower(ltrim($query)), 0, strlen("select")) == "select") {
             $result_value = intval($result);
             $this->current_row[$result_value] = -1;
             if ($limit > 0) {
                 $this->limits[$result_value] = array($first, $limit, 0);
             }
             $this->highest_fetched_row[$result_value] = -1;
         } else {
             $this->affected_rows = odbc_num_rows($result);
             odbc_free_result($result);
         }
     } else {
         $this->SetODBCError("Do query", "Could not execute a ODBC database query \"{$query}\"", $php_errormsg);
     }
     return $result;
 }
Example #23
0
<meta charset="utf-8">
<link rel="stylesheet" href="estilos/style.css">

<?php 
include "conecta_mysql.inc.php";
$nomeProduto = $_POST["nomeProduto"];
$descricaoproduto = $_POST["descricaoProduto"];
$precProduto = $_POST["precProduto"];
$desconto = $_POST["desconto"];
$idCategoria = $_POST["idCategoria"];
$ativoProduto = $_POST["ativoProduto"];
$idUsuario = $_SESSION['idUsuario'];
$qtdMinEstoque = $_POST["qtdMinEstoque"];
$tmpName = $_FILES['foto']['tmp_name'];
$fp = fopen($tmpName, 'r');
$img = fread($fp, filesize($tmpName));
fclose($fp);
$params = array($nomeProduto, $descricaoproduto, $precProduto, $desconto, $idCategoria, $ativoProduto, $idUsuario, $qtdMinEstoque, $img);
$instrucaoSQL = "insert into produto(nomeProduto, descproduto, precproduto,descontoPromocao, idCategoria,ativoProduto,idUsuario, qtdMinestoque, imagem)  values (?,?,?,?,?,?,?,?,?)";
$rec = odbc_prepare($connect, $instrucaoSQL);
var_dump($rec);
odbc_execute($rec, $params);
?>

Example #24
0
} else {
    $colnames = odbc_exec($client->get_connection(), "SELECT column_name, data_type, data_length FROM ALL_TAB_COLUMNS WHERE table_name = '" . strtoupper($table_name) . "';");
    $q2 = "";
    for ($i = 1; $i <= $fields_count; ++$i) {
        if (!odbc_fetch_row($colnames)) {
            die("false");
        }
        if ($i < $fields_count) {
            $q2 .= odbc_result($colnames, 1) . " = ?,\n";
        } else {
            $q2 .= odbc_result($colnames, 1) . " = ?\n";
        }
    }
    $query = "UPDATE " . $table_name . " SET " . $q2 . " WHERE ROWID = ?;";
}
$statement = odbc_prepare($client->get_connection(), $query);
if ($statement === false) {
    die($query . "\n\n" . get_odbc_error());
}
$items = array();
for ($i = 1; $i <= $fields_count; ++$i) {
    if (isset($_POST["is_null"]) && isset($_POST["is_null"][$i]) && $_POST["is_null"][$i] == true) {
        $items[] = null;
    } else {
        $items[] = $_POST["value"][$i];
    }
}
if ($rowid != null) {
    $items[] = $rowid;
}
$result = odbc_execute($statement, $items);
Example #25
0
echo "resource? " . is_resource($rv) . "\n";
if (!$rv) {
    echo "odbc_execute failed!\n";
    echo odbc_errormsg();
    echo odbc_close($r);
    exit(1);
}
$rows = odbc_num_rows($rh);
echo "num rows: {$rows}\n";
var_dump($rows);
// fetch
while ($rr = odbc_fetch_array($rh)) {
    var_dump($rr);
}
//////////////////// params
$rh = odbc_prepare($r, "SELECT ATAN(?,?)");
if (!$rh) {
    echo "odbc_prepare failed!\n";
    echo odbc_errormsg();
    echo odbc_close($r);
    exit(1);
}
//var_dump($rh);
echo "resource? " . is_resource($rh) . "\n";
$rv = odbc_execute($rh, array('-2', '2'));
//var_dump($rv);
echo "resource? " . is_resource($rv) . "\n";
if (!$rv) {
    echo "odbc_execute failed!\n";
    echo odbc_errormsg();
    echo odbc_close($r);
Example #26
0
  <td><?php 
                echo odbc_field_len($info, $i);
                ?>
</td>
 </tr>
<?php 
            }
            odbc_free_result($info);
            ?>
</table>

Inserting data:
<?php 
            echo "{$gif1file} - {$gif2file} - {$gif3file}";
            odbc_free_result($res);
            $res = odbc_prepare($conn, "insert into php_test values(?,?)");
            if ($gif1file != "none") {
                $params[0] = "image1";
                $params[1] = "'{$gif1file}'";
                odbc_execute($res, $params);
            }
            if ($gif2file != "none") {
                $params[0] = "image2";
                $params[1] = "'{$gif2file}'";
                odbc_execute($res, $params);
            }
            if ($gif3file != "none") {
                $params[0] = "image3";
                $params[1] = "'{$gif3file}'";
                odbc_execute($res, $params);
            }
 public function query($query, $security = array())
 {
     $this->query = odbc_prepare($this->connect, $query);
     odbc_execute($this->query, $security);
     return $this->query;
 }
Example #28
0
 /**
  * @param string $sql query execute
  * @param array $params not worked
  * @return boolean
  */
 public function execute($sql, $params = [])
 {
     $stmt = odbc_prepare($this->activeConnect, $sql);
     odbc_execute($stmt, $params);
     return true;
 }
Example #29
0
 function _query($sql, $inputarr = false)
 {
     global $php_errormsg;
     if (isset($php_errormsg)) {
         $php_errormsg = '';
     }
     $this->_error = '';
     if ($inputarr) {
         if (is_array($sql)) {
             $stmtid = $sql[1];
         } else {
             $stmtid = odbc_prepare($this->_connectionID, $sql);
             if ($stmtid == false) {
                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
                 return false;
             }
         }
         if (!odbc_execute($stmtid, $inputarr)) {
             //@odbc_free_result($stmtid);
             if ($this->_haserrorfunctions) {
                 $this->_errorMsg = odbc_errormsg();
                 $this->_errorCode = odbc_error();
             }
             return false;
         }
     } else {
         if (is_array($sql)) {
             $stmtid = $sql[1];
             if (!odbc_execute($stmtid)) {
                 //@odbc_free_result($stmtid);
                 if ($this->_haserrorfunctions) {
                     $this->_errorMsg = odbc_errormsg();
                     $this->_errorCode = odbc_error();
                 }
                 return false;
             }
         } else {
             $stmtid = odbc_exec($this->_connectionID, $sql);
         }
     }
     $this->_lastAffectedRows = 0;
     if ($stmtid) {
         if (@odbc_num_fields($stmtid) == 0) {
             $this->_lastAffectedRows = odbc_num_rows($stmtid);
             $stmtid = true;
         } else {
             $this->_lastAffectedRows = 0;
             odbc_binmode($stmtid, $this->binmode);
             odbc_longreadlen($stmtid, $this->maxblobsize);
         }
         if ($this->_haserrorfunctions) {
             $this->_errorMsg = '';
             $this->_errorCode = 0;
         } else {
             $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
         }
     } else {
         if ($this->_haserrorfunctions) {
             $this->_errorMsg = odbc_errormsg();
             $this->_errorCode = odbc_error();
         } else {
             $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
         }
     }
     return $stmtid;
 }
Example #30
0
 /**
  * this function used for special stored procedure call only
  * 
  * @param $conn
  * @param $stmt
  * @param $bindArray
  * @return string
  */
 public function execXMLStoredProcedure($conn, $stmt, $bindArray)
 {
     $crsr = odbc_prepare($conn, $stmt);
     if (!$crsr) {
         $this->setError($conn);
         return false;
     }
     // extension problem: sends warning message into the php_log or stdout
     // about number of result sets. (switch on return code of SQLExecute()
     // SQL_SUCCESS_WITH_INFO
     if (!@odbc_execute($crsr, array($bindArray['internalKey'], $bindArray['controlKey'], $bindArray['inputXml']))) {
         $this->setError($conn);
         return "ODBC error code: " . $this->getErrorCode() . ' msg: ' . $this->getErrorMsg();
     }
     // disconnect operation cause crush in fetch, nothing appears as sql script.
     $row = '';
     $outputXML = '';
     if (!$bindArray['disconnect']) {
         while (odbc_fetch_row($crsr)) {
             $tmp = odbc_result($crsr, 1);
             if ($tmp) {
                 // because of ODBC problem blob transferring should execute some "clean" on returned data
                 if (strstr($tmp, "</script>")) {
                     $pos = strpos($tmp, "</script>");
                     $pos += strlen("</script>");
                     // @todo why append this value?
                     $row .= substr($tmp, 0, $pos);
                     break;
                 } else {
                     $row .= $tmp;
                 }
             }
         }
         $outputXML = $row;
     }
     return $outputXML;
 }