zoukankan      html  css  js  c++  java
  • php mysqli query 查询数据库后读取内容的方法

    php mysqli query 查询数据库后读取内容的方法

    <?php
    $mysqli 
    = new mysqli("localhost""my_user""my_password""world");

    /* check connection */
    if ($mysqli->connect_errno) {
        
    printf("Connect failed: %s "$mysqli->connect_error);
        exit();
    }

    /* Create table doesn't return a resultset */
    if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
        
    printf("Table myCity successfully created. ");
    }

    /* Select queries return a resultset */
    if ($result $mysqli->query("SELECT Name FROM City LIMIT 10")) {
        
    printf("Select returned %d rows. "$result->num_rows);

        
    /* free result set */
        
    $result->close();
    }

    /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
    if ($result $mysqli->query("SELECT * FROM City"MYSQLI_USE_RESULT)) {

        
    /* Note, that we can't execute any functions which interact with the
           server until result set was closed. All calls will return an
           'out of sync' error */
        
    if (!$mysqli->query("SET @a:='this will not work'")) {
            
    printf("Error: %s "$mysqli->error);
        }
        
    $result->close();
    }

    $mysqli->close();
    ?>

    实例代码:

    $sql="select * from qa limit 0,10";
     $result=$mysqli->query($sql);
     while ($row = mysqli_fetch_assoc($result))
      {
        echo "question_title : {$row['question_title']} <br>";
        echo "answer_content1: {$row['answer_content1']} <br>";
      }
     /* free result set */
        $result->close();

    参考文档:http://www.php.net/manual/en/mysqli.query.php

  • 相关阅读:
    用shell脚本监控进程是否存在 不存在则启动的实例
    vue+element-ui+ajax实现一个表格的实例
    c的指针和php中的引用的区别
    mysql or条件查询优化
    Linq查询操作之投影操作
    Linq查询操作之Where筛选
    Linq专题之查询操作
    linq之join子句
    linq之let子句
    linq之into子句
  • 原文地址:https://www.cnblogs.com/zdz8207/p/3745486.html
Copyright © 2011-2022 走看看