• mysqli链接数据库示例代码


    $mysqli = new mysqli("localhost", "数据库用户名", "数据库密码", "数据库名称");
    	
    	/*
    	 * This is the "official" OO way to do it,
    	 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
    	 */
    	if ($mysqli->connect_error) {
    		die('Connect Error (' . $mysqli->connect_errno . ') '
    				. $mysqli->connect_error);
    	}
    	$mysqli->query("SET NAMES 'utf8'");
    	$result = $mysqli->query("SELECT * FROM 数据表 LIMIT 10");
    	
    	/* Select queries return a resultset */
    	if ($result->num_rows > 0) {
    		
    		$row = $result->fetch_assoc();
    		echo $row["title"];
    
    		/* free result set */
    		$result->close();
    	}
    	
    	$mysqli->close();
    
    <?php
    header('Content-Type:text/html;Charset=utf-8');
    $db = new mysqli();
    $db->connect('localhost','root',0123,'test');
    $db->set_charset('utf8');
    $sql='select * from pw_luck';
    $query=$db->query($sql);
    
    echo '<pre>';
    while($rs=mysqli_fetch_array($query)){
        $result[]=$rs;
    }
    $i=0;
    print_r($result);
    echo '</pre><hr>';
    foreach($result as $key=>$value){
        //if($i%2==0){
        echo $key.'<->'.$value[0].'<->'.$value[1].'<->'.$value[2].'<->'.$value[3].'<hr>';
        //}
        $i+=1;
    }
    $query->free();
    $db->close();
  • 相关阅读:
    LOJ6395 「THUPC2018」城市地铁规划 / City
    [题解] 好好
    [题解] CF1316F Battalion Strength
    【题解】CF1320D Reachable Strings
    【题解】夕张的改造
    【题解】期望次数
    [FJWC2020] lg
    Django 多表操作
    Django 单表操作
    Django 模板层 静态文件
  • 原文地址:https://www.cnblogs.com/qingsong/p/6612669.html
Copyright © 2020-2023  润新知