public function salvarProduto($produto, $preco) { $codigo = $produto->getCodigo(); $nome = $produto->getNome(); $descricao = $produto->getDescricao(); $imagem = $produto->getUrlImagem(); $compra = $preco->getCompra(); $venda = $preco->getVenda(); $revenda = $preco->getReVenda(); /* * conecta o banco de dados */ $con = new JqsConnectionFactory(); $link = $con->conectar(); $query = "INSERT INTO tb_produtos (codigo_produto, nome_produto, descricao_produto, url_imagem) \n\t\tvalues('{$codigo}', '{$nome}', '{$descricao}', '{$imagem}')"; $query2 = "INSERT INTO tb_precos (preco_compra, preco_venda, preco_revenda, id_produto_preco) \n\t\tvalues('{$compra}', '{$venda}', '{$revenda}', last_insert_id() )"; try { mysqli_autocommit($link, FALSE); mysqli_query($link, $query) or die(mysqli_error($link) . "Produto"); mysqli_query($link, $query2) or die(mysqli_error($link) . "Preço"); mysqli_commit($link); mysqli_autocommit($link, TRUE); } catch (Exception $e) { mysqli_rollback($link); echo $e; } }
function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @mysqli_autocommit($this->db_connect_id, false); $this->transaction = true; break; case 'commit': $result = @mysqli_commit($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); $this->transaction = false; if (!$result) { @mysqli_rollback($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); } break; case 'rollback': $result = @mysqli_rollback($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); $this->transaction = false; break; default: $result = true; } return $result; }
public function commit() { if (phpversion() < '5.5.0') { mysqli_autocommit($this->connection, TRUE); } // return mysqli_autocommit($this->connection, TRUE); mysqli_commit($this->connection); }
public function connect() { if ($this->link = mysqli_connect($this->host, $this->user, $this->pass)) { $this->exception("Could not connect to the database!"); } mysqli_select_db($this->link, $this->name); mysqli_autocommit($this->link, false); }
public function commit() { if (mysqli_commit($this->conn)) { mysqli_autocommit($this->conn, true); } else { throw new server_except('cannot commit transaction'); } }
public function rollback() { if (mysqli_rollback($this->connection)) { mysqli_autocommit($this->connection, $this->autoCommit = true); } else { throw new Sabel_Db_Exception_Driver(mysql_error($this->connection)); } }
function __construct($servername, $username, $password, $database) { $this->con = mysqli_connect($servername, $username, $password, $database); if (!$this->con) { $this->error = mysqli_connect_error(); mysqli_autocommit($this->con, FALSE); } return $this->con; }
function bind_twice($link, $engine, $sql_type1, $sql_type2, $bind_type1, $bind_type2, $bind_value1, $bind_value2, $offset) { if (!mysqli_query($link, "DROP TABLE IF EXISTS test_mysqli_stmt_bind_param_type_juggling_table_1")) { printf("[%03d + 1] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); return false; } mysqli_autocommit($link, true); $sql = sprintf("CREATE TABLE test_mysqli_stmt_bind_param_type_juggling_table_1(col1 %s, col2 %s) ENGINE=%s", $sql_type1, $sql_type2, $engine); if (!mysqli_query($link, $sql)) { printf("[%03d + 2] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); return false; } if (!($stmt = mysqli_stmt_init($link))) { printf("[%03d + 3] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); return false; } if (!mysqli_stmt_prepare($stmt, "INSERT INTO test_mysqli_stmt_bind_param_type_juggling_table_1(col1, col2) VALUES (?, ?)")) { printf("[%03d + 4] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); return false; } if (!mysqli_stmt_bind_param($stmt, $bind_type1 . $bind_type2, $bind_value1, $bind_value1)) { printf("[%03d + 5] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); return false; } if (!mysqli_stmt_execute($stmt)) { printf("[%03d + 6] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); return false; } if (!mysqli_stmt_bind_param($stmt, $bind_type1 . $bind_type2, $bind_value1, $bind_value2)) { printf("[%03d + 7] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); return false; } if (!mysqli_stmt_execute($stmt)) { printf("[%03d + 8] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); return false; } mysqli_stmt_close($stmt); if (!($res = mysqli_query($link, "SELECT col1, col2 FROM test_mysqli_stmt_bind_param_type_juggling_table_1"))) { printf("[%03d + 9] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); return false; } if (2 !== ($tmp = mysqli_num_rows($res))) { printf("[%03d + 10] Expecting 2 rows, got %d rows [%d] %s\n", $offset, $tmp, mysqli_errno($link), mysqli_error($link)); } $row = mysqli_fetch_assoc($res); if ($row['col1'] != $bind_value1 || $row['col2'] != $bind_value1) { printf("[%03d + 11] Expecting col1 = %s, col2 = %s got col1 = %s, col2 = %s - [%d] %s\n", $offset, $bind_value1, $bind_value1, $row['col1'], $row['col2'], mysqli_errno($link), mysqli_error($link)); return false; } $row = mysqli_fetch_assoc($res); if ($row['col1'] != $bind_value1 || $row['col2'] != $bind_value2) { printf("[%03d + 12] Expecting col1 = %s, col2 = %s got col1 = %s, col2 = %s - [%d] %s\n", $offset, $bind_value1, $bind_value2, $row['col1'], $row['col2'], mysqli_errno($link), mysqli_error($link)); return false; } mysqli_free_result($res); return true; }
public function dbConnect() { $this->conn1 = @mysqli_connect($this->db_hostname, $this->db_username, $this->db_password, $this->db_name); if (!$this->conn1) { die(mysqli_connect_error()); } $this->db1 = mysqli_select_db($this->conn1, $this->db_name) or die(mysqli_error($this->conn1)); mysqli_autocommit($this->conn1, TRUE); return $this->conn1; }
static function setAutoCommit($con, $autoCommit) { try { $v = mysqli_autocommit($con, $autoCommit); if (!$v) { throw new Exception("Can not set commit automatically."); } } catch (Exception $e) { REDLog::writeErrLog($e->getMessage()); } }
function __construct() { if (!$this->conectarSGBD()) { die("A conexão com o servidor não foi estabelecida!"); } if (!$this->selecionarBanco()) { die("A conexão com o servidor não foi estabelecida!"); } if (!mysqli_autocommit($this->conexao, false)) { die("Auto comite não ativado!"); } }
function openConn() { // Create connection $conn = mysqli_connect(); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } mysqli_autocommit($conn, FALSE); // echo "Connected successfully <br>"; $conn->select_db("dmhweborg"); return $conn; }
function createDbConnection($host, $username, $password, $dbname, $port = null) { if (!$port) { $dbConnection = mysqli_connect($host, $username, $password, $dbname); } else { $dbConnection = mysqli_connect($host, $username, $password, $dbname, $port); } if (!$dbConnection) { die('Could not connect: ' . mysqli_connect_error()); } $dbConnection->set_charset("utf8"); mysqli_autocommit($dbConnection, FALSE); return $dbConnection; }
public function dbNewMessage($email, $name, $website, $message) { $email = mysqli_real_escape_string($this->link, $email); $name = mysqli_real_escape_string($this->link, $name); $website = mysqli_real_escape_string($this->link, $website); $message = mysqli_real_escape_string($this->link, $message); mysqli_autocommit($this->link, FALSE); $query = "INSERT INTO CONTACT(pk_contact,name,email,website,message) \n\t\t\t\t VALUES('NULL','{$name}','{$email}','{$website}','{$message}')"; mysqli_query($this->link, $query); if (mysqli_errno($this->link)) { return -1; } else { mysqli_commit($this->link); return 1; } }
public function EndTransaction() { if (!$this->in_transazione) { return 0; } if ($this->Commit()) { mysqli_autocommit($this->conn, true); $this->in_transazione = false; return 1; } else { $this->Rollback(); autocommit($this->conn, true); $this->in_transazione = false; return 0; } }
function commandDataBase($sql) { $conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname); if ($conn->connect_error) { die('Connection failed: ' . $conn->connect_error); } mysqli_autocommit($conn, FALSE); if ($conn->query($sql) === TRUE) { mysqli_commit($conn); return true; } else { mysqli_rollback($conn); return false; } $conn->close(); }
public function getDbConnection($host, $username, $password, $dbname, $port) { if (!$this->dbConnection) { if (!$port) { $this->dbConnection = mysqli_connect($host, $username, $password, $dbname); } else { $this->dbConnection = mysqli_connect($host, $username, $password, $dbname, $port); } } if (!$this->dbConnection) { die('Could not connect: ' . mysqli_connect_error()); } $this->dbConnection->set_charset("utf8"); mysqli_autocommit($this->dbConnection, FALSE); return $this->dbConnection; }
/** * Connect to database server * * @access public * @return boolean Connection successful */ public function connect() { //----------------------------------------- // Done SQL prefix yet? //----------------------------------------- $this->_setPrefix(); //----------------------------------------- // Load query file //----------------------------------------- $this->_loadCacheFile(); //----------------------------------------- // Connect //----------------------------------------- /* Did we add a port inline? */ if (!$this->obj['sql_port'] and strstr($this->obj['sql_host'], ':')) { list($host, $port) = explode(':', $this->obj['sql_host']); $this->obj['sql_host'] = $host; $this->obj['sql_port'] = intval($port); } if ($this->obj['sql_port']) { $this->connection_id = @mysqli_connect($this->obj['sql_host'], $this->obj['sql_user'], $this->obj['sql_pass'], $this->obj['sql_database'], $this->obj['sql_port']); } else { $this->connection_id = @mysqli_connect($this->obj['sql_host'], $this->obj['sql_user'], $this->obj['sql_pass'], $this->obj['sql_database']); } if (!$this->connection_id) { $this->connect_failed = true; $this->throwFatalError(); return FALSE; } mysqli_autocommit($this->connection_id, TRUE); //----------------------------------------- // Remove sensitive data //----------------------------------------- unset($this->obj['sql_host']); unset($this->obj['sql_user']); unset($this->obj['sql_pass']); //----------------------------------------- // If there's a charset set, run it //----------------------------------------- if ($this->obj['sql_charset']) { $this->query("SET NAMES '{$this->obj['sql_charset']}'"); } parent::connect(); return TRUE; }
/** * (Lazy) connect. * * @throws Exception */ private function connect() { // Was a custom port supplied with host? $port = null; if (strpos($this->host, ':') !== false) { list($this->host, $port) = explode(':', $this->host); } $this->link = mysqli_connect(($this->persistent ? 'p:' : '') . $this->host, $this->username, $this->password, $this->dbname, $port); if (!$this->link) { unset($this->link); throw new Exception('Unable to connect database'); } mysqli_autocommit($this->link, false); // in general, we need one commit over page mysqli_set_charset($this->link, 'utf8'); // must have to correct mysqli_real_escape_string! $this->beginTransaction(); }
/** * 连接数据库 * * @return void */ public function connect() { if (!$this->_link) { $mysqli = mysqli_connect($this->_host, $this->_user, $this->_pass, '', $this->_port); if (!$mysqli) { die("{$this->_host}: 数据库服务器连接失败"); } if ($mysqli->connect_error) { $this->_showError("{$this->_host}: 数据库服务器连接失败"); exit; } $this->_link = $mysqli; mysqli_autocommit($this->_link, true); if ($this->_dbname) { $this->useDb($this->_dbname); } } }
function updateRecord($arrayValues, $table, $condition, $autoCommit = "yes") { include_once 'connection.php'; mysqli_autocommit($conn, false); $table_value = ""; if (empty($arrayValues)) { echo "Incomplete Parameters Passed"; die; } if (!is_array($arrayValues)) { echo "Parameter Passed is not an Array"; return false; } foreach ($arrayValues as $ind => $v) { //$table_value .= $ind . "= '" . $v . "',"; $firstChar = substr($v, 0, 1); if ($firstChar == '(') { $table_value .= $ind . "= " . $v . ","; } else { $table_value .= $ind . "= '" . $v . "',"; } } $table_value = substr($table_value, 0, -1); try { $sql = "UPDATE {$table} SET {$table_value} WHERE {$condition}"; //Check if inserted to table, if not rollback mysqli_query($conn, $sql); if (mysqli_errno($conn)) { $errno = mysqli_errno($conn); mysqli_rollback($conn); return "error"; } else { if ($autoCommit == "yes") { mysqli_commit($conn); return true; } else { return true; } } } catch (Exception $e) { mysqli_rollback($conn); return "error"; } }
function __construct($toRoot = NULL) { if (!($xml = simplexml_load_file($toRoot . "configuracao.xml"))) { trigger_error('Erro ao ler o arquivo XML', E_USER_ERROR); } $this->hostBanco = $xml->bancoDeDados->host; $this->usuarioBanco = $xml->bancoDeDados->nomeUsuario; $this->senhaBanco = $xml->bancoDeDados->senha; $this->nomeBanco = $xml->bancoDeDados->nomeBanco; if (!$this->conectarSGBD()) { die("A conexão com o servidor não foi estabelecida!"); } if (!$this->selecionarBanco()) { die("Não foi possivel selecionar o banco no servidor!"); } if (!mysqli_autocommit($this->conexao, false)) { die("Auto comite não ativado!"); } }
public function dbNewMessage($email, $name, $mobile, $country, $state, $address, $message) { $email = mysqli_real_escape_string($this->link, $email); $name = mysqli_real_escape_string($this->link, $name); $message = mysqli_real_escape_string($this->link, $message); $mobile = mysqli_real_escape_string($this->link, $mobile); $state = mysqli_real_escape_string($this->link, $state); $country = mysqli_real_escape_string($this->link, $country); $address = mysqli_real_escape_string($this->link, $address); mysqli_autocommit($this->link, FALSE); $query = "INSERT INTO contact(pk_contact,name,mobile,email,country,state,address,message) \n\t\t\t\t VALUES('NULL','{$name}','{$mobile}','{$email}','{$country}','{$state}','{$address}','{$message}')"; mysqli_query($this->link, $query); if (mysqli_errno($this->link)) { return -1; } else { mysqli_commit($this->link); return 1; } }
/** * SQL Transaction * @access private */ function _sql_transaction($status = 'begin') { switch ($status) { case 'begin': return @mysqli_autocommit($this->db_connect_id, false); break; case 'commit': $result = @mysqli_commit($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); return $result; break; case 'rollback': $result = @mysqli_rollback($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); return $result; break; } return true; }
private function getConnection($host, $user, $password, $db_name) { $pos = strpos($host, ':'); if ($pos && $pos != 1) { $port = (int) substr($host, $pos + 1); $host = substr($host, 0, $pos); } else { $port = 3306; } $link = mysqli_connect($host, $user, $password, $db_name, $port); mysqli_autocommit($link, true); if (!$link) { throw new MysqlException('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } $this->set_charset($this->charset, $link); if (!empty($this->timezone)) { $this->query('SET time_zone="' . $this->timezone . '"', $link); } return $link; }
function TransactionQuery($sqlmultipleinput, $connection) { // turn off autocommit, and then start a transaction mysqli_autocommit($connection, FALSE); mysqli_begin_transaction($connection, MYSQLI_TRANS_START_READ_ONLY); $i = 0; $output = ""; foreach ($sqlmultipleinput as $sql) { // replace SpecialLastID with mysql_insert_id($connection) $sql = str_replace("SpecialLastID", "" . mysqli_insert_id($connection) . "", $sql); //echo "Query = ".$sql."\n"; // do query list($result, $valid) = DoQuery($sql, $connection); $outout[$i] = array($result, $valid); $i++; } // end commit transaction, and set autocommit for future $transresult = mysqli_commit($connection); mysqli_autocommit($connection, TRUE); return array($transresult, $output); }
/** * Transaction style - runs queries in order * * @since 08.05.2011 * Refactored for using $this::mysqli_connection instead of mysqli_init/mysqli_close */ public function executeMultiNoresSQL(&$queryArry) { $link = $this->getMysqliConnection(); /* set autocommit to off */ mysqli_autocommit($link, FALSE); $all_query_ok = true; //do queries foreach ($queryArry as $query) { if (!mysqli_real_query($link, $query)) { $all_query_ok = false; } } if ($all_query_ok) { /* commit queries */ mysqli_commit($link); } else { /* Rollback */ mysqli_rollback($link); } /* set autocommit to on */ mysqli_autocommit($link, TRUE); return $all_query_ok; }
/** * Connect to the database. * * @param string $host Hostname * @param string $user Username * @param string $password Password * @param string $database The database to connect to * @param int $port The portnumber to use for connecting * @param string $charset The charset to use * * @return mixed Connection status */ public function doConnect($host, $user, $password, $database, $port, $charset) { /* establish connection */ if (empty($this->m_link_id)) { if (empty($port)) { $port = null; } $this->m_link_id = @mysqli_connect($host, $user, $password, $database, $port); if (!$this->m_link_id) { $this->halt($this->getErrorMsg()); return $this->_translateError(); } /* set character set */ if (!empty($charset)) { Tools::atkdebug("Set database character set to: {$charset}"); $this->_query("SET NAMES '{$charset}'", true); } /* set autoCommit to off */ mysqli_autocommit($this->m_link_id, false); } /* return link identifier */ return self::DB_SUCCESS; }
public function salvarCliente($cliente, $endereco) { $nome = $cliente->getNome(); $fone = $cliente->getFone(); $email = $cliente->getEmail(); $instagran = $cliente->getInstagran(); $indicacao = $cliente->getIndicacao(); $tipo = $cliente->getTipo(); $whatsapp = $cliente->getWhatsapp(); $aniversario = $cliente->getAniversario(); $facebook = $cliente->getFacebook(); //$endereco = new Endereco(); $logradouro = $endereco->getLogradouro(); $numero = $endereco->getNumero(); $bairro = $endereco->getBairro(); $cidade = $endereco->getCidade(); $estado = $endereco->getEstado(); $cep = $endereco->getCep(); $complemento = $endereco->getComplemento(); /* * conecta o banco de dados */ $con = new JqsConnectionFactory(); $link = $con->conectar(); $query = "INSERT INTO tb_clientes (nome_cliente, fone_cliente, email_cliente, instagran_cliente, indicacao_cliente, tipo_cliente, whatsapp_cliente, aniversario_cliente, facebook_cliente) \n\t\tvalues('{$nome}', '{$fone}', '{$email}', '{$instagran}', '{$indicacao}', '{$tipo}', '{$whatsapp}', '{$aniversario}', '{$facebook}')"; $query2 = "INSERT INTO tb_enderecos (logradouro_endereco, numero_endereco, bairro_edereco, cidade_endereco, \n\t\testado_endereco, cep_endereco, complemento_endereco, id_cliente_endereco) values('{$logradouro}','{$numero}',\n\t\t'{$bairro}', '{$cidade}', '{$estado}', '{$cep}', '{$complemento}', last_insert_id())"; try { mysqli_autocommit($link, FALSE); mysqli_query($link, $query) or die(mysqli_error($link) . "cliente"); mysqli_query($link, $query2) or die(mysqli_error($link) . "endereço"); mysqli_commit($link); mysqli_autocommit($link, TRUE); } catch (Exception $e) { mysqli_rollback($link); echo $e; } }
public function executeMultiNoresSQL(&$queryArry) { $link = mysqli_init(); if (!$link) { throw new DBAdapter2Exception("mysqli_init failed"); } if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) { throw new DBAdapter2Exception("Setting MYSQLI_OPT_CONNECT_TIMEOUT failed"); } if (!mysqli_real_connect($link, $this->host, $this->username, $this->password, $this->schema)) { throw new DBAdapter2Exception('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } if (!mysqli_set_charset($link, $this->charset)) { throw new DBAdapter2Exception('Error loading character set ' . $this->charset . ' - ' . mysqli_error($link)); } /* set autocommit to off */ mysqli_autocommit($link, FALSE); $all_query_ok = true; //do queries foreach ($queryArry as $query) { if (!mysqli_real_query($link, $query)) { $all_query_ok = false; } } if ($all_query_ok) { /* commit queries */ mysqli_commit($link); } else { /* Rollback */ mysqli_rollback($link); } /* set autocommit to on */ mysqli_autocommit($link, TRUE); mysqli_close($link); return $all_query_ok; }