zoukankan      html  css  js  c++  java
  • php连接mysql...mysqli和mysql

      mysql_connect()这一系列函数已经不推荐使用了,不安全。  

    <?php
    
    $con = mysql_connect('localhost','root','');// 选择连接数据库系统
    if(!$con){
        die('no con...' . mysql_error());
    }
    mysql_select_db('test', $con);// 选择哪个数据库
    
    $sql = 'select * from hello limit 1,2';// sql
    $re = mysql_query($sql, $con);// 查询,结果是个资源
    
    while($row = mysql_fetch_array($re)){// mysql_fetch_assoc
        print_r($row);
    }

      现在推荐使用mysqli的系列函数。

    <?php
    
    // 参数分别是:主机名 用户名 密码 数据库名称 端口
    $con = mysqli_connect('localhost','root','','test');// 这里已经包括数据库名称
    
    $sql = 'select * from hello limit 1,2';
    $re = mysqli_query($con, $sql);
    
    while($row = mysqli_fetch_assoc($re)){
        print_r($row);
    }

    -

  • 相关阅读:
    算法市场 Algorithmia
    Cucumber
    TeamCity 持续集成工具
    自动化测试
    Selenium
    Android耗时操作
    RecyclerView
    Android报错
    Lakeshore
    BaaS_后端即服务 RESTful
  • 原文地址:https://www.cnblogs.com/firstForEver/p/4940497.html
Copyright © 2011-2022 走看看