• PHP mysqli类


     1 <?php
     2     header("content-type:text/html;charset=utf-8");
     3     $conn = new mysqli("localhost","root","root","test"); //ip、username、password、dbname
     4     $conn->query("set names utf8");    //设置编码
     5     
     6     $sql = "SELECT * FROM TEST";
     7     $result = $conn->query($sql);
     8     
     9     while ($row = $result->fetch_assoc()) {
    10         echo $row["name"];
    11         echo "<br/>";
    12     }
    13     while ($row = $result->fetch_row()) {
    14         echo $row[0];
    15         echo "<br/>";
    16     }
    17     
    18     $sql = "INSERT INTO TEST(id) VALUES(2)";
    19     $conn->query($sql);
    20     if($conn->affected_rows>0) {
    21         echo $conn->insert_id;
    22     } else {
    23         echo -1;
    24     }
    25     
    26     $conn->autocommit(FALSE); //默认是自动提交的,设置为不自动提交,才可以使用事务
    27     $sql1 = ".....";
    28     $sql2 = ".....";
    29     $conn->query($sql1);
    30     $conn->query($sql2);
    31     if(!$conn->errno) {
    32         $conn->commit();
    33     } else {
    34         $conn->rollback();
    35     }
    36 
    37 ?>
  • 相关阅读:
    Tarjan专题
    Catalan数
    状压DP
    威尔逊定理证明:
    【fzoj 2376】「POJ2503」Babelfish
    Android 源码
    Android实现推送方式解决方案
    Android apk 签名
    圆角的实现
    Android 资源
  • 原文地址:https://www.cnblogs.com/JeromeZ/p/5796066.html
Copyright © 2020-2023  润新知