本文整理汇总了PHP中mysqli::begin_transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli::begin_transaction方法的具体用法?PHP mysqli::begin_transaction怎么用?PHP mysqli::begin_transaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli
的用法示例。
在下文中一共展示了mysqli::begin_transaction方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param string $sql
* @param array $queryParams
*
* @return bool|\mysqli_result
* @throws Mysql
*/
public function execute(string $sql, $queryParams = [])
{
// log the query
$this->log_sql($sql, $queryParams);
// start sql transaction
$this->mysqli->begin_transaction();
// use cache to get prepared statement
$statement = $this->get_statement_from_sql($sql);
// bind params
if (is_array($queryParams) && !empty($queryParams)) {
$bindTypes = '';
foreach ($queryParams as $name => $value) {
$bindTypes .= static::get_bind_type($value);
}
$statement->bind_param($bindTypes, ...$queryParams);
}
// execute statement
if (!$statement->execute()) {
$this->mysqli->rollback();
throw new Mysql($statement->error, $statement->errno, null, $sql);
}
// commit this transaction
$this->mysqli->commit();
// save info for latest query
$this->insertId = $statement->insert_id;
$this->affectedRows = $statement->affected_rows;
return $statement->get_result();
}
示例2: begin
/**
* Start a transaction. While MySQL does support "Nested Transactions" of
* sorts (see http://dev.mysql.com/doc/refman/5.0/en/savepoint.html), we're
* not going to support them here. If we're already in a transaction,
* silently ignore the request.
*
* @returns \Docnet\Db
* @throws \Exception if mysqli::begin_transaction() returned false
* @since 19/May/14 support for PHP 5.4 using query('BEGIN')
*/
public function begin()
{
if ($this->bol_in_transaction) {
return $this;
}
if (PHP_VERSION_ID >= 50500) {
$bol_success = $this->obj_db->begin_transaction();
} else {
$bol_success = $this->obj_db->query('BEGIN');
}
if ($bol_success) {
$this->bol_in_transaction = true;
} else {
throw new \Exception("Failed to start a transaction");
}
return $this;
}
示例3: max
define('redirect', '../missions/index.php');
include "../partials/member_header.php";
$request->enable_super_globals();
include '/../config/config.php';
// Create connection
$connection = new mysqli($mysql_servername, $mysql_username, $mysql_password, $mysql_database, $mysql_serverport);
// Check connection
if ($connection->connect_error) {
die("Problem connecting to the database");
}
$connection->autocommit(false);
$current_framework_version = 0;
$current_framework_version_query = <<<SQL
select max(id) as id from framework;
SQL;
$connection->begin_transaction();
if ($results = $connection->query($current_framework_version_query)) {
while ($row = $results->fetch_assoc()) {
$current_framework_version = $row['id'];
}
} else {
$error = $connection->error;
error_log("{$error}");
exit;
}
$order = "order by m.created_on desc";
$having = "having count(mts.id) < 1";
switch ($_GET['filter']) {
case 1:
$having = "having count(mts.id) > 0";
$order = "order by max(s.date) desc";
示例4: beginTransaction
/**
* Leave autocommit mode and begin a transaction.
*
* @return Adapter
*/
public function beginTransaction()
{
if (!$this->_isConnected) {
$this->_connect();
}
if ($this->_profiler) {
$q = $this->_profiler->queryStart('begin', Profiler::TRANSACTION);
}
parent::begin_transaction();
if ($this->_profiler) {
$this->_profiler->queryEnd($q);
}
return $this;
}
示例5: beginTransaction
public function beginTransaction()
{
return method_exists(static::$db, 'begin_transaction') ? static::$db->begin_transaction() : $this->execute('START TRANSACTION');
}
示例6: mysqli
<?php
session_start();
$mysqli = new mysqli('127.0.0.1', 'phptest', 'phptest', 'phptest');
if ($mysqli->connect_error) {
echo $mysqli->connect_error;
exit;
} else {
$mysqli->set_charset("utf8");
}
$mysqli->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
$id = session_id();
/* select value */
if (!($stmt = $mysqli->prepare("SELECT value FROM {$id}"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->bind_result($value);
while ($stmt->fetch()) {
$mysqldata = $value;
$values .= "<br>value={$value}<br>";
}
// 行数の取得
$stmt->store_result();
// これ忘れるとnum_rowsは0
$rows .= "rows=" . $stmt->num_rows . "<br>";
$stmt->close();
// transaction commit
mysqli_commit($link);
示例7: onPreQuery
public function onPreQuery(\mysqli $mysqli)
{
$mysqli->begin_transaction();
}
示例8: htmlspecialchars
//score clicked = 10;
// nonClicked = -1;
//TODO: cambiar para que solo se envíen votos positivos
if (isset($_GET["clicked"]) && isset($_GET["userName"]) && is_numeric($_GET["clicked"])) {
//INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;
$userName = htmlspecialchars($_GET["userName"]);
$clicked = (int) $_GET["clicked"];
$db = new mysqli("localhost", "names", "como1cerda=)", "names");
if ($db->connect_errno) {
printf("Connect failed: %s\n", $db->connect_error);
http_response_code(500);
//500: internal server error
exit;
} else {
try {
$db->begin_transaction();
$query = "INSERT INTO votos (id, idName, user, score, count) VALUES (?, ?, '{$userName}', 1, 1) ON DUPLICATE KEY UPDATE score=score+1, count=count+1";
if (!($stmt = $db->prepare($query))) {
echo "Prepare failed: (" . $db->errno . ") " . $db->error;
}
$stmt->bind_param('si', $i, $in);
//clicked
$i = "'{$userName}{$clicked}'";
$in = $clicked;
$stmt->execute();
$stmt->close();
$db->commit();
echo "ok";
} catch (Exception $e) {
$db->rollBack();
echo "<br>";
示例9: begin
public static function begin()
{
self::$mysqli->begin_transaction();
self::$isTransaction = true;
}
示例10: mysqli
<?php
$servername = "localhost";
$username = "admin";
$password = $_POST["password"];
$dbname = "raticals";
$conn = new mysqli($servername, $username, $password, $dbname);
$failure = false;
if ($conn->connect_error) {
error_log("Connection failed: " . $conn->connect_error);
$failure = true;
} else {
if (!$failure && !$conn->begin_transaction(MYSQLI_TRANS_START_READ_WRITE)) {
error_log("begin transaction failure:" . $conn->error);
$failure = true;
} else {
$create_event = $conn->prepare("INSERT INTO event (title, street, city, state, zip, datetime) VALUES (?, ?, ?, ?, ?, ?)");
$create_event->bind_param("ssssss", $title, $street, $city, $state, $zip, $datetime);
$title = $_POST["title"];
$street = $_POST["street"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$datetime_input = $_POST["date"] . " " . $_POST["time"];
$datetime_obj = DateTime::createFromFormat("d/m/Y g:ia", $datetime_input);
if (!$datetime_obj) {
error_log("Failed to construct DateTime from '" . $datetime_input . "':" . $conn->error);
$failure = true;
} else {
$datetime = $datetime_obj->format("y-m-d G:i:s");
if (!$create_event->execute()) {
示例11: beginTransaction
/**
* Начало транзакции
*
* @return bool
* Возвращает TRUE в случае успешного завершения
* или FALSE в случае возникновения ошибки.
*/
public function beginTransaction()
{
return $this->db->begin_transaction();
}
示例12: function
* @author bergstein@trickyplan.com
* @description MySQL Driver
* @package Codeine
* @version 8.x
*/
setFn('Open', function ($Call) {
F::Log('Connecting to ' . $Call['Server'] . ' via ' . $Call['User'], LOG_INFO);
$Link = new mysqli($Call['Server'], $Call['User'], F::Live($Call['Password']));
if (!$Link->ping()) {
F::Log($Link->connect_error, LOG_CRIT, 'Administrator');
return null;
}
F::Log($Link->host_info, LOG_INFO, 'Administrator');
$Link->select_db($Call['Database']);
$Link->set_charset($Call['Charset']);
$Link->begin_transaction();
// $Link->autocommit ($Call['AutoCommit']);
return $Link;
});
setFn('Operation', function ($Call) {
$Call['MySQL Result'] = $Call['Link']->query($Call['Query']);
if ($Call['Link']->errno != 0) {
F::Log($Call['Query'], LOG_ERR, 'Administrator');
F::Log($Call['Link']->errno . ':' . $Call['Link']->error, LOG_ERR, 'Administrator');
$Call = F::Hook('MySQL.Error.' . $Call['Link']->errno, $Call);
} else {
F::Log($Call['Query'], LOG_INFO, 'Administrator');
F::Counter('MySQL');
}
return $Call;
});
示例13: inserir
function inserir()
{
$conexao = new mysqli('localhost', 'root', '@ipe789@', 'pizza');
$conexao->begin_transaction();
$query = "INSERT INTO `tb_pedido`(`cd_funcionario`, `cd_cliente`, `bo_pedido`, `dt_pedido`)\n values('" . implode("','", $this->dados()) . "')";
$resulto = $conexao->query($query);
if ($resulto == true) {
$cd_pedido = $conexao->insert_id;
// pizza
if (isset($_REQUEST['pizza'])) {
$piz = $_REQUEST['pizza'];
foreach ($piz as $value) {
$pizza['cd_pedido'] = $cd_pedido;
$pizza['cd_pizza'] = $value;
$query = "INSERT INTO `tb_pedido_pizza`(`cd_pedido`, `cd_pizza`)\n values('" . implode("','", $pizza) . "')";
$res = $conexao->query($query);
}
}
// fim pizza
// Adicional
if ($res == true) {
if (isset($_REQUEST['adc'])) {
$adcional = $_REQUEST['adc'];
foreach ($adcional as $value) {
$adc['cd_pedido'] = $cd_pedido;
$adc['cd_adicionais'] = $value;
$query = "INSERT INTO `tb_pedido_adicionais`(`cd_pedido`, `cd_adicionais`)\n values('" . implode("','", $adc) . "')";
if ($conexao->query($query)) {
$bo_adc = true;
} else {
$bo_adc = false;
}
}
} else {
$bo_adc = true;
}
} else {
print "Erro Ao Salvar Pizza";
return;
}
// fim adicional
// Bebidas
if ($bo_adc == true) {
$bebida = $_REQUEST['bebida'];
foreach ($bebida as $value) {
$be['cd_pedido'] = $cd_pedido;
$be['cd_bebida'] = $value;
$query = "INSERT INTO `tb_pedido_bebida`(`cd_pedido`, `cd_bebida`)\n values('" . implode("','", $be) . "')";
$bo_bebida = $conexao->query($query);
}
} else {
print "Erro Ao Salvar ADC";
return;
}
// Commita Salva se tiver tudo Ok
if ($bo_bebida == true) {
$conexao->commit();
print "Salvo Com sucesso";
return $cd_pedido;
} else {
print "Erro Ao Salvar Bebidas";
return;
}
}
$conexao->close();
}