zoukankan      html  css  js  c++  java
  • PHP use MySQLi

    1. connection

      $mysqli = new mysqli($host,$user,$passwd,$db,$port);
        if ($mysqli->connect_errno) {
            echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }

    2. select query

    $sql="SELECT name FROM users2";
        if (!$mysqli->real_query($sql)){
            printf("Errormessage: %s<br>", $mysqli->error);
        }
        $result = $mysqli->use_result();
    
        echo "Result set :<br>";
        // use numeric array
        while ($row = $result->fetch_array()) {
            echo " name = " . $row[0] ."<br>";
        }
        // use associate array
    //    while ($row = mysqli_fetch_assoc($result)){
    //        echo " name = " . $row['name'] ."<br>";
    //    }

     3. complete code

    <?php
        $host="localhost";
        $user="root";
        $passwd="123";
        $db="test";
        $port="3307";
    
        $mysqli = new mysqli($host,$user,$passwd,$db,$port);
        if ($mysqli->connect_errno) {
            echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }
        $sql="SELECT name FROM users2";
        if (!$mysqli->real_query($sql)){
            printf("Errormessage: %s<br>", $mysqli->error);
        }
        $result = $mysqli->use_result();
    
        echo "Result set :<br>";
        // use numeric array
        while ($row = $result->fetch_array()) {
            echo " name = " . $row[0] ."<br>";
        }
        // use associate array
    //    while ($row = mysqli_fetch_assoc($result)){
    //        echo " name = " . $row['name'] ."<br>";
    //    }
    ?>
  • 相关阅读:
    Linux从程序到进程
    Linux用户与“最小权限”原则
    Linux进程关系
    Linux信号基础
    Linux进程基础
    Sublime Text 报“Pylinter could not automatically determined the path to lint.py
    Linux文本流
    Linux文件管理相关命令
    Linux命令行与命令
    Linux架构
  • 原文地址:https://www.cnblogs.com/phoenix13suns/p/4550778.html
Copyright © 2011-2022 走看看