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; }
/** * DB transaction commit * this method is private * @return boolean */ function _commit() { $connection = $this->_getConnection('master'); mysqli_commit($connection); $this->setQueryLog(array('query' => 'COMMIT')); return true; }
public function commit() { if (!\mysqli_commit($this->connection)) { throw new \Exception('Could not start Transaction: ' . \mysqli_error($this->connection)); } return true; }
function updateInformation($sql, $conn) { global $gpa, $degree, $school, $graduationDate, $resumeID, $additionalInfomation, $status, $resumeUserID; try { // Connect to database if ($sql == "create") { $userCreateSQL = "INSERT INTO Resume_Post (gpa,degree,school,graduationDate,resumeID,additionalInfomation,userID,status) VALUES (?,?,?,STR_TO_DATE( ? , '%Y-%m-%d'),?,?,?,?)"; $stmt = $conn->prepare($userCreateSQL); $stmt->bind_param('ssssssss', $gpa, $degree, $school, $graduationDate, $resumeID, $additionalInfomation, $resumeUserID, $status); } else { $userUpdateSQL = "UPDATE Resume_Post SET gpa= ? , degree= ? , school= ?, graduationDate = STR_TO_DATE( ? , '%Y-%m-%d'), resumeID= ?, additionalInfomation= ?, status= ? WHERE resumeID= ? AND userID= ? "; $stmt = $conn->prepare($userUpdateSQL); $stmt->bind_param('sssssssss', $gpa, $degree, $school, $graduationDate, $resumeID, $additionalInfomation, $status, $resumeID, $resumeUserID); } //$sql = "UPDATE Resume_Post SET gpa= 3.96 , degree= 'bachelor' , school= 'UT', graduationDate = STR_TO_DATE( '2015-12-12' , '%Y-%m-%d'), resumeID= 2, additionalInfomation= 'No much', status= 1 WHERE resumeID= 2 AND userID= 'meng.da'"; //$conn->query($sql); // Execute and Check Errors $stmt->execute(); $err = $stmt->error; if ($err) { $conn->rollback(); $error_msg = "Some unknown database error occurred. Please inform database administrator with these error messages.<br>\nError message : " . $err . "<br>"; echo $error_msg; return 0; } else { // Commit transaction mysqli_commit($conn); return 1; } } catch (mysqli_sql_exception $e) { echo $e->__toString(); } }
public function insertItems(Items $items) { $con = self::openConnection(); $affected = 0; mysqli_begin_transaction($con); $stm = mysqli_stmt_init($con); $sql = "INSERT INTO category VALUES (?, ?, ?)"; mysqli_stmt_prepare($stm, $sql); foreach ($items->getItems() as $item) { $code = $item->getCode(); $name = $item->getName(); $parent = $item->getParent() == null ? null : $item->getParent()->getCode(); mysqli_stmt_bind_param($stm, 'sss', $code, $name, $parent); mysqli_stmt_execute($stm); if (mysqli_affected_rows($con) == 1) { $affected++; } } if ($affected > 0) { mysqli_commit($con); } else { mysqli_rollback($con); } return $affected; }
public function insertItems(Items $items) { $con = self::openConnection(); $affected = 0; mysqli_begin_transaction($con); $stm = mysqli_stmt_init($con); $sql = "INSERT INTO product VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; mysqli_stmt_prepare($stm, $sql); foreach ($items->getItems() as $item) { $code = $item->getCode(); $articul = $item->getArticul(); $name = $item->getName(); $bmuID = $item->getBasicMeasurementUnit() == null ? null : $item->getBasicMeasurementUnit()->getId(); $price = $item->getPrice(); $curID = $item->getCurrency() == null ? null : $item->getCurrency()->getId(); $muID = $item->getMeasurementUnit() == null ? null : $item->getMeasurementUnit()->getId(); $parent = $item->getParent() == null ? null : $item->getParent()->getCode(); mysqli_stmt_bind_param($stm, 'sssdddds', $code, $articul, $name, $bmuID, $price, $curID, $muID, $parent); mysqli_stmt_execute($stm); if (mysqli_affected_rows($con) == 1) { $affected++; } } if ($affected > 0) { mysqli_commit($con); } else { mysqli_rollback($con); } return $affected; }
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 commit() { if (mysqli_commit($this->connection)) { mysqli_autocommit($this->connection, $this->autoCommit = true); } else { throw new Sabel_Db_Exception_Driver(mysql_error($this->connection)); } }
public function commit() { if (mysqli_commit($this->conn)) { mysqli_autocommit($this->conn, true); } else { throw new server_except('cannot commit transaction'); } }
public function Commit() { if ($this->in_transazione) { return mysqli_commit($this->conn); } else { return 0; } }
public function commit() { parent::commit(); if (!mysqli_commit($this->link)) { $this->set_driver_error(null, PDO::ERRMODE_EXCEPTION, 'commit'); } $this->setAttribute(PDO::ATTR_AUTOCOMMIT, 1); return true; }
static function commit($con) { try { $v = mysqli_commit($con); if (!$v) { throw new Exception("Error commit to database."); } } catch (Exception $e) { REDLog::writeErrLog($e->getMessage()); } }
public function encerraTransacao($lErro) { $this->lTransacao = false; if ($lErro) { $lRetorno = mysqli_rollback($this->conn); } else { $lRetorno = mysqli_commit($this->conn); } $this->fecharConexao(); return $lRetorno; }
function query($query, &$output) { $output = array(); $result = @mysqli_query($this->link, $query); if (!$result) { return FALSE; } if ($result !== TRUE) { while ($row = mysqli_fetch_array($result)) { $output[] = $row; } } mysqli_commit($this->link); return $output; }
function update($columns, $values, $condition) { global $dbtable, $dbconn; $query = "UPDATE " . $dbtable . " SET " . $columns . "=" . $values . " WHERE " . $condition . ";"; $op = mysqli_query($dbconn, $query); if (!$op || $op === false) { echo mysqli_error($dbconn) . "<br>"; var_dump($query); echo "<br>"; var_dump($op); echo "<br>"; return false; } mysqli_commit($dbconn); return true; }
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; } }
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(); }
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 insert_store_data($city_name) { global $con; //read the json file contents $URL = 'http://api.walmartlabs.com/v1/stores?apiKey=7hbsnck6acm8sh2nr8w4m3pc&city=' . $city_name . '&format=json'; //$URL= 'http://api.walmartlabs.com/v1/stores?apiKey=7hbsnck6acm8sh2nr8w4m3pc&city=newark&format=json'; $jsonResult = file_get_contents($URL); print_r($jsonResult); //convert json object to php associative array $result = json_decode($jsonResult, true); //print_r($result); //$iCount=count($result); for ($i = 0; $i < sizeof($result); $i++) { $s_no = mysqli_real_escape_string($result[$i]["no"]); $name = mysqli_real_escape_string($result[$i]["name"]); $country = mysqli_real_escape_string($result[$i]['country']); $lat = mysqli_real_escape_string($result[$i]['coordinates'][0]); $long = mysqli_real_escape_string($result[$i]['coordinates'][1]); $address = mysqli_real_escape_string($result[$i]['streetAddress']); $state = mysqli_real_escape_string($result[$i]['stateProvCode']); $city = mysqli_real_escape_string($result[$i]['city']); $zip = mysqli_real_escape_string($result[$i]['zip']); $phone = mysqli_real_escape_string($result[$i]['phoneNumber']); $sunday_open = mysqli_real_escape_string($result[$i]['sundayOpen']); $timezones = mysqli_real_escape_string($result[$i]['timezone']); print_r($s_no); print_r($lat); print_r($long); print_r($zip); print_r($phone); //insert into mysql table /*$sql = "INSERT INTO `stores` (s_no,name,country,lat,long,address,city,state_code,zip,phone,sunday_open,timezones) VALUES('" . $s_no . "', '" . $name . "', '" . $country . "', '" . $lat . "','" . $long . "', '" . $address . "', '" . $city . "', '" . $state . "', '" . $zip . "', '" . $phone . "', '" . $sunday_open . "','" . $timezones . "')";*/ mysqli_query($con, "INSERT INTO `store2` (s_no,name,country,lat,long,address,city,state_code,zip,phone,sunday_open,timezones)\n VALUES('" . $s_no . "', '" . $name . "', '" . $country . "', '" . $lat . "','" . $long . "', '" . $address . "', '" . $city . "', '" . $state . "', '" . $zip . "', '" . $phone . "', '" . $sunday_open . "','" . $timezones . "')"); /* if(!mysqli_query($con,$sql)) { die('Error : Databse not copied' . mysql_error()); }*/ mysqli_commit($con); echo "Copied to database sucessfully"; sleep(3); } }
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; }
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); }
public function insertUnits(Units $units) { $con = self::openConnection(); $affected = 0; mysqli_begin_transaction($con); $stm = mysqli_stmt_init($con); $sql = "INSERT INTO currency (code) VALUE (?)"; mysqli_stmt_prepare($stm, $sql); foreach ($units->getUnits() as $unit) { $code = $unit->getCode(); mysqli_stmt_bind_param($stm, 's', $code); mysqli_stmt_execute($stm); if (mysqli_affected_rows($con) == 1) { $affected++; } } if ($affected > 0) { mysqli_commit($con); } else { mysqli_rollback($con); } return $affected; }
/** * 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; }
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; } }
function execute_sqls_in_mysql($sql) { //putenv("ORACLE_HOME=/home/oracle/OraHome1"); //putenv("ORACLE_SID=orcl"); $connection = mysqli_connect("pdb7.awardspace.net", "1561537_test", "mydbtest1", "1561537_test"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } foreach ($sql as $value) { $cursor = mysqli_query($connection, $value); if ($cursor == false) { //display_oracle_error_message($cursor); mysqli_close($connection); // sql failed die("SQL execution Failed"); } // commit the result mysqli_commit($connection); } mysqli_close($connection); $return_array["flag"] = $result; $return_array["cursor"] = $cursor; return $return_array; }
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; }
function insert($id_usuario, $id_archivo, $texto) { require_once 'dbm.php'; $ret = false; if ($texto == "" or $id_usuario == "" or $id_archivo == "") { return false; } $datab = new DataBase(); $datab->open(); $connect = $datab->get_connect(); if (mysqli_connect_errno()) { return false; } mysqli_autocommit($connect, FALSE); $query = "INSERT INTO comentario(id_archivo, id_usuario, fecha, texto) VALUES ({$id_archivo}, {$id_usuario}, NOW(), '{$texto}');"; if (mysqli_query($connect, $query) == false) { return false; } if (mysqli_commit($connect)) { $ret = true; } mysqli_close($connect); return $ret; }
function sqlCommRollChanges($sql_error, $sqlLink, $pcn) { $response = ""; if ($sql_error == 0) { mysqli_commit($sqlLink); $response['message'] = "The course " . $pcn . " was successfully added to your watch-list"; } else { mysqli_rollback($sqlLink); $response['message'] = "There was an error processing your request. Please try again later."; } echo json_encode($response); exit(0); }