• mysqli的使用


    <?php
    /**
    数据库连接
    
    **/
    $conn=mysqli_connect('localhost:3306','root','root');
    if(!$conn){
        die("could not connect:".mysqli_error($conn));
    }
    mysqli_query($conn , "set names utf8");
    $sec=mysqli_select_db($conn,'wc');
    if(!$sec){
        die("error".mysqli_error($conn));
    }
    $sql="select * from ss";
    $retval=mysqli_query($conn,$sql);
    if(!$retval){
        die("无法读取数据:".mysqli_error($conn));
    }
    print_r($retval);
    while($row=mysqli_fetch_array($retval,MYSQLI_ASSOC)){
        echo '<br/>';
        print_r($row);
        $arr[]=$row;
    }
    var_dump($arr);
    mysqli_free_result($retval);
    mysqli_close($conn);
    /*3中解析方法
    mysqli_fetch_array($retval)查询结果
    Array ( [0] => 1 [id] => 1 [1] => 12 [a] => 12 [2] => 34 [b] => 34 [3] => 11 [c] => 11 ) 
    Array ( [0] => 2 [id] => 2 [1] => 65 [a] => 65 [2] => 42 [b] => 42 [3] => 16 [c] => 16 ) 
    Array ( [0] => 3 [id] => 3 [1] => 91 [a] => 91 [2] => 95 [b] => 95 [3] => 93 [c] => 93 )
    mysqli_fetch_array($retval,MYSQLI_ASSOC)
    Array ( [id] => 1 [a] => 12 [b] => 34 [c] => 11 ) 
    Array ( [id] => 2 [a] => 65 [b] => 42 [c] => 16 ) 
    Array ( [id] => 3 [a] => 91 [b] => 95 [c] => 93 )
    
    mysqli_fetch_assoc($retval)查询结果
    Array ( [id] => 1 [a] => 12 [b] => 34 [c] => 11 ) 
    Array ( [id] => 2 [a] => 65 [b] => 42 [c] => 16 ) 
    Array ( [id] => 3 [a] => 91 [b] => 95 [c] => 93 )
    //mysqli_fetch_row($retval)
    Array ( [0] => 1 [1] => 12 [2] => 34 [3] => 11 ) 
    Array ( [0] => 2 [1] => 65 [2] => 42 [3] => 16 ) 
    Array ( [0] => 3 [1] => 91 [2] => 95 [3] => 93 )
    //mysqli_fetch_field($retval)
    stdClass Object ( [name] => id [orgname] => id [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 1 [length] => 11 [charsetnr] => 63 [flags] => 49667 [type] => 3 [decimals] => 0 ) 
    stdClass Object ( [name] => a [orgname] => a [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 2 [length] => 11 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 ) 
    stdClass Object ( [name] => b [orgname] => b [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 2 [length] => 11 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 ) 
    stdClass Object ( [name] => c [orgname] => c [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 2 [length] => 11 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 )
    */
  • 相关阅读:
    ATS(App Transport Security)对HTTP协议屏蔽引起的问题
    后台子线程(非主线程)更新UI引起的警告
    Xcode无法启动ios模拟器的问题
    UIButton修改文字大小问题
    imageNamed和imageWithContentsOfFile-无法加载图片的问题
    storyboard在ios模拟器无法显示的问题
    返回一个数组的连续子数组和的最大值
    第二周学习进度总结
    软件工程开学第一节课课堂测试
    第一周学习进度总结
  • 原文地址:https://www.cnblogs.com/huay/p/10386206.html
Copyright © 2020-2023  润新知