当前位置: 首页>>代码示例>>PHP>>正文


PHP mysqli_begin_transaction函数代码示例

本文整理汇总了PHP中mysqli_begin_transaction函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_begin_transaction函数的具体用法?PHP mysqli_begin_transaction怎么用?PHP mysqli_begin_transaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mysqli_begin_transaction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insertItems

 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;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:25,代码来源:CategoryDAO.php

示例2: trans

 public function trans()
 {
     if (!\mysqli_begin_transaction($this->connection, MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT)) {
         throw new \Exception('Could not start Transaction: ' . \mysqli_error($this->connection));
     }
     return true;
 }
开发者ID:webcraftmedia,项目名称:system,代码行数:7,代码来源:ConnectionMYS.php

示例3: insertItems

 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;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:30,代码来源:ProductDAO.php

示例4: beginTransaction

 public function beginTransaction()
 {
     if (phpversion() < '5.5.0') {
         return mysqli_autocommit($this->connection, FALSE);
     } else {
         return mysqli_begin_transaction($this->connection);
     }
 }
开发者ID:songfarm-david,项目名称:Songfarm,代码行数:8,代码来源:database.php

示例5: iniciaTransacao

 public function iniciaTransacao()
 {
     if (is_null($this->conn)) {
         $this->conectar();
     }
     $this->lTransacao = mysqli_begin_transaction($this->conn);
     return $this->lTransacao;
 }
开发者ID:ricardosander,项目名称:petshop,代码行数:8,代码来源:MySQL.php

示例6: _begin

 /**
  * DB transaction start
  * this method is private
  * @return boolean
  */
 function _begin($transactionLevel = 0)
 {
     $connection = $this->_getConnection('master');
     if (!$transactionLevel) {
         if (function_exists('mysqli_begin_transaction')) {
             mysqli_begin_transaction($connection);
             $this->setQueryLog(array('query' => 'START TRANSACTION'));
         } else {
             $this->_query("START TRANSACTION" . $point, $connection);
         }
     } else {
         $this->_query("SAVEPOINT SP" . $transactionLevel, $connection);
     }
     return true;
 }
开发者ID:rhymix,项目名称:rhymix,代码行数:20,代码来源:DBMysqli_innodb.class.php

示例7: readUnits

 public function readUnits()
 {
     $con = self::openConnection();
     $measurements = new Measurements();
     mysqli_begin_transaction($con);
     $sql = "SELECT * FROM measurement WHERE 1";
     $res = mysqli_query($con, $sql);
     while ($arrRes = mysqli_fetch_assoc($res)) {
         $measurement = new Measurement();
         $measurement->setId($arrRes['id']);
         $measurement->setCode($arrRes['code']);
         $measurements->setUnit($measurement);
     }
     return $measurements;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:15,代码来源:MeasurementDAO.php

示例8: readUnits

 public function readUnits()
 {
     $con = self::openConnection();
     $currencies = new Currencies();
     mysqli_begin_transaction($con);
     $sql = "SELECT * FROM currency WHERE 1";
     $res = mysqli_query($con, $sql);
     while ($arrRes = mysqli_fetch_assoc($res)) {
         $currency = new Currency();
         $currency->setId($arrRes['id']);
         $currency->setCode($arrRes['code']);
         $currencies->setUnit($currency);
     }
     return $currencies;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:15,代码来源:CurrencyDAO.php

示例9: TransactionQuery

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);
}
开发者ID:Roblix711,项目名称:AssistMe,代码行数:21,代码来源:connection.php

示例10: _performTransaction

 protected function _performTransaction($parameters = null)
 {
     if (function_exists('mysqli_begin_transaction')) {
         return mysqli_begin_transaction($this->link);
     } else {
         return mysqli_autocommit($this->link, false);
     }
 }
开发者ID:Sarjuuk,项目名称:DbSimple,代码行数:8,代码来源:Mysqli.php

示例11: Database_beginTransaction

function Database_beginTransaction($dbConnect)
{
    mysqli_begin_transaction($dbConnect);
}
开发者ID:Archerol,项目名称:booking,代码行数:4,代码来源:database.php

示例12: printf

    }
}
/* does it really set a flag? */
if (mysqli_get_server_version($link) >= 50605) {
    if (!mysqli_begin_transaction($link, MYSQLI_TRANS_START_READ_ONLY, sprintf("flag %d", $flag))) {
        printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
    if (mysqli_query($link, "INSERT INTO test(id) VALUES (2)")) {
        printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    } else {
        if (!mysqli_commit($link)) {
            printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
        } else {
            $res = mysqli_query($link, "SELECT id FROM test WHERE id = 2");
        }
    }
}
if (!mysqli_begin_transaction($link, -1)) {
    printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (mysqli_get_server_version($link) >= 50605) {
    /* does it like stupid names? */
    if (@(!$link->begin_transaction(MYSQLI_TRANS_START_READ_WRITE, "*/trick me?\n"))) {
        printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
    /* does it like stupid names? */
    if (@(!$link->begin_transaction(MYSQLI_TRANS_START_READ_WRITE, "az09"))) {
        printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
}
print "done!";
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_begin_transaction.php

示例13: parseFutureCourseOfferingsFile

 private static function parseFutureCourseOfferingsFile($file_path, $academicQuarterID)
 {
     $servername = "127.0.0.1";
     $username = "root";
     $password = "";
     $dbname = "csc_webapp";
     // Create connection
     $conn = mysqli_connect($servername, $username, $password, $dbname);
     if (!$conn) {
         return "Failed to connect to database";
     }
     mysqli_autocommit($conn, false);
     mysqli_begin_transaction($conn);
     $file = fopen($file_path, "r");
     if ($file) {
         while (($line = fgets($file)) !== false) {
             $split = explode("~", $line);
             if (count($split) < 11) {
                 continue;
             }
             $courseName = trim($split[0]);
             $courseNumber = trim($split[1]);
             $courseSectionName = trim($split[2]);
             $callNumber = trim($split[3]);
             $creditHours = trim($split[4]);
             $courseTitle = trim($split[5]);
             $days = trim($split[6]);
             $startTime = trim($split[7]);
             if (strlen($startTime) > 0) {
                 if (strpos($startTime, "AM") !== false) {
                     $startTimePM = false;
                     $startTime = str_replace("AM", "", $startTime);
                 } else {
                     if (strpos($startTime, "PM") !== false) {
                         $startTimePM = true;
                         $startTime = str_replace("PM", "", $startTime);
                     }
                 }
                 $startTimeSplit = explode(":", $startTime);
                 $startTimeHour = intval($startTimeSplit[0]);
                 $startTimeMinute = intval($startTimeSplit[1]);
                 if ($startTimePM && $startTimeHour < 12) {
                     $startTimeHour += 12;
                 }
             }
             $endTime = trim($split[8]);
             if (strlen($endTime) > 0) {
                 if (strpos($endTime, "AM") !== false) {
                     $endTimePM = false;
                     $endTime = str_replace("AM", "", $endTime);
                 } else {
                     if (strpos($endTime, "PM") !== false) {
                         $endTimePM = true;
                         $endTime = str_replace("PM", "", $endTime);
                     }
                 }
                 $endTimeSplit = explode(":", $endTime);
                 $endTimeHour = intval($endTimeSplit[0]);
                 $endTimeMinute = intval($endTimeSplit[1]);
                 if ($endTimePM && $endTimeHour < 12) {
                     $endTimeHour += 12;
                 }
             }
             $startTime = $startTimeHour * 100 + $startTimeMinute;
             $endTime = $endTimeHour * 100 + $endTimeMinute;
             $roomName = trim($split[9]);
             $instructor = trim($split[10]);
             $selectQuery = "SELECT CourseID FROM `Courses` WHERE `CourseName` = '{$courseName}' AND `CourseNumber` = '{$courseNumber}' LIMIT 1";
             $results = mysqli_query($conn, $selectQuery);
             if (mysqli_num_rows($results) > 0) {
                 $arr = mysqli_fetch_assoc($results);
                 $courseID = $arr['CourseID'];
                 $insertQuery = "INSERT INTO `CourseSections` (`CourseID`, `SectionName`, `Hours`, `InstructorName`, `CallNumber`, `AcademicQuarterID`) VALUES ({$courseID}, '{$courseSectionName}', {$creditHours}, '{$instructor}', {$callNumber}, {$academicQuarterID})";
                 mysqli_query($conn, $insertQuery);
                 $id = mysqli_insert_id($conn);
                 for ($i = 0; $i < strlen($days); $i++) {
                     $dayOfWeekLetter = $days[$i];
                     if ($dayOfWeekLetter == 'M' || $dayOfWeekLetter == 'm') {
                         $dayOfWeek = Course_section_time_model::DAY_MONDAY;
                     } else {
                         if ($dayOfWeekLetter == 'T' || $dayOfWeekLetter == 't') {
                             $dayOfWeek = Course_section_time_model::DAY_TUESDAY;
                         } else {
                             if ($dayOfWeekLetter == 'W' || $dayOfWeekLetter == 'w') {
                                 $dayOfWeek = Course_section_time_model::DAY_WEDNESDAY;
                             } else {
                                 if ($dayOfWeekLetter == 'R' || $dayOfWeekLetter == 'r') {
                                     $dayOfWeek = Course_section_time_model::DAY_THURSDAY;
                                 } else {
                                     if ($dayOfWeekLetter == 'F' || $dayOfWeekLetter == 'f') {
                                         $dayOfWeek = Course_section_time_model::DAY_FRIDAY;
                                     } else {
                                         $dayOfWeek = "";
                                     }
                                 }
                             }
                         }
                     }
                     if (strlen($dayOfWeek) > 0) {
                         $insertQuery = "INSERT INTO `CourseSectionTimes` (`CourseSectionID`, `DayOfWeek`, `StartTime`, `EndTime`) VALUES ({$id}, '{$dayOfWeek}', {$startTime}, {$endTime})";
//.........这里部分代码省略.........
开发者ID:Troutzorz,项目名称:csapp,代码行数:101,代码来源:Futurecourses.php

示例14: beginTransaction

 function beginTransaction()
 {
     mysqli_begin_transaction($this->con);
 }
开发者ID:jorge-panes,项目名称:php-DBConnection-generic-methods,代码行数:4,代码来源:DBConnection.php

示例15: insert

 public function insert()
 {
     $db = new DBConnection();
     $link = $db->connect();
     if ($link != null) {
         $query = "";
         if ($this->entity_type == 'Member') {
             //mysqli_report(MYSQLI_REPORT_ALL);
             $obj = $this->entity;
             $FirstName = $obj->getFirstName();
             $LastName = $obj->getLastName();
             $DeptName = $obj->getDeptName();
             $RegisterDate = $obj->getRegisterDate();
             $Email = $obj->getEmail();
             $Mobile = $obj->getMobile();
             $Gender = $obj->getGender();
             $Facultyname = $obj->getFacultyname();
             $Birthday = $obj->getBirthday();
             $Bloodgroup = $obj->getBloodgroup();
             $Nic = $obj->getNic();
             $Address = $obj->getAddress();
             $IndexNu = $obj->getIndexNu();
             $password = '$2y$13$0aW6zsmFJEZKWgS8o5kK..U3KOP6mWC6rBl9VLPvEMuH6j8/1mLlO';
             $roles = 'a:2:{i:0;s:10:"ROLE_ADMIN";i:1;s:9:"ROLE_USER";}';
             $isActice = 1;
             $last_id = null;
             mysqli_autocommit($link, FALSE);
             try {
                 mysqli_begin_transaction($link);
                 $query = $link->prepare("INSERT INTO member (first_name,last_name,dept_name,register_date,email,mobile,gender,faculty_name,birthday,bloodgroup,NIC,address,index_no) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
                 $query->bind_param("sssssssssssss", $FirstName, $LastName, $DeptName, $RegisterDate, $Email, $Mobile, $Gender, $Facultyname, $Birthday, $Bloodgroup, $Nic, $Address, $IndexNu);
                 $query->execute();
                 $last_id = mysqli_insert_id($link);
                 $result = mysqli_query($link, "INSERT INTO app_user(id,email,password,role,is_active) VALUES({$last_id},'" . $Email . "','" . $password . "','" . $roles . "','" . $isActice . "')");
                 mysqli_commit($link);
                 return $last_id;
             } catch (Exception $e) {
                 mysqli_rollback($link);
                 return null;
             }
         } elseif ($this->entity_type == 'Sport') {
             mysqli_report(MYSQLI_REPORT_ALL);
             $obj = $this->entity;
             $title = $obj->getTitle();
             $totPlayers = $obj->getTotalPlayers();
             $type = $obj->getType();
             $query = $link->prepare("INSERT INTO sport  (title ,tot_players ,type) VALUES (?,?,?)");
             $query->bind_param("sss", $title, $totPlayers, $type);
             $query->execute();
         } elseif ($this->entity_type == 'PracticalSchedule') {
             $studentID = $this->entity->getStudentID();
             $instructorID = $this->entity->getInstructorID();
             $sportID = $this->entity->getSportID();
             $slotName = $this->entity->getSportName();
             $day = $this->entity->getDay();
             $query = $link->prepare("INSERT INTO practical_schedule(s_id,i_id,sport_id,slot_name,day) VALUES(?,?,?,?,?)");
             $query->bind_param("iiiss", $studentID, $instructorID, $sportID, $slotName, $day);
             $query->execute();
         } elseif ($this->entity_type == 'Officer') {
             $memberID = $this->entity->getMemberId();
             $roles = $this->entity->getRoles();
             $appointedDate = $this->entity->getAppointedDate();
             $query = $link->prepare("INSERT INTO officer(s_id,appointed_date,roles) VALUES (?,?,?)");
             $query->bind_param("iss", $memberID, $appointedDate, $roles);
             $query->execute();
         } elseif ($this->entity_type == 'Event') {
             mysqli_report(MYSQLI_REPORT_ALL);
             $obj = $this->entity;
             $eName = $obj->getEventName();
             $tParticipants = $obj->getTotalparticipant();
             $eType = $obj->getEventtype();
             $startDate = $obj->getStartdate();
             $endDate = $obj->getEndDate();
             $startTime = $obj->getStartTime();
             $endTime = $obj->getEndTime();
             $budget = $obj->getBudget();
             $description = $obj->getDescription();
             $location = $obj->getLocation();
             $eventIncharge = $obj->getEventIncharge();
             // Set autocommit to off
             mysqli_autocommit($link, FALSE);
             mysqli_query($link, "INSERT INTO event (event_name,tot_participants,event_type,start_date,end_date,start_time,end_time,budget,description,location)\n                VALUES ('" . $eName . "','" . $tParticipants . "','" . $eType . "','" . $startDate . "','" . $endDate . "','" . $startTime . "','" . $endTime . "','" . $budget . "','" . $description . "','" . $location . "')");
             $last_id = mysqli_insert_id($link);
             mysqli_query($link, "INSERT INTO event_incharge (o_id,event_id) VALUES ('" . $eventIncharge . "','" . $last_id . "')");
             mysqli_commit($link);
         } elseif ($this->entity_type == 'Resource') {
             mysqli_report(MYSQLI_REPORT_ALL);
             $category = $this->entity->getCategory();
             $description = $this->entity->getDescription();
             $registrationDate = $this->entity->getRegDate();
             $typeId = $this->entity->getTypeId();
             $value = $this->entity->getValue();
             $query = $link->prepare("INSERT INTO resource_registration(category,description,registration_date,type_id,value) VALUES (?,?,?,?,?)");
             $query->bind_param("sssii", $category, $description, $registrationDate, $typeId, $value);
             $query->execute();
         } elseif ($this->entity_type == 'DynamicAllocation') {
             mysqli_report(MYSQLI_REPORT_ALL);
             $memberID = $this->entity->getMemberId();
             $typeID = $this->entity->getTypeId();
             $issuedDate = $this->entity->getIssuedDate();
//.........这里部分代码省略.........
开发者ID:lahiiru,项目名称:moraspirit,代码行数:101,代码来源:DBAccess.php


注:本文中的mysqli_begin_transaction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。