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

     $con=mysqli_connect('localhost','root','root')      连接数据库 后面参数为账号和密码  连接成功返回mysql连接标识符  连接失败返回false

    mysqli_select_db($con,'t1') 选择数据库      成功为true,失败为false
    mysql_query("set names 'utf8'");  设置使用的字符编码

    mysqli_close($con)  关闭连接

    mysqli_query($con,'set names utf8');  设置为utf8编码格式 
    mysqli_query($con,'insert demo(username,age,password) values("ali","19","123321")')    插入内容

    echo mysqli_error($con);  输入mysql错误信息

    $query = mysqli_query($con,'select username,password from music');
    while($row=mysqli_fetch_row($query)){    获取返回的值 通过索引
    printf ("%s (%s) ", $row[0], $row[1]);
    }

    $result=mysqli_query($con,'select * from music');
    $row = mysqli_fetch_array($result);    可以通过索引和值 比如$row['username']
    echo $row[0], $row['password'];

     

    $result=mysqli_query($con,'select * from music');
    $row = mysqli_fetch_array($result,MYSQLI_ASSOC);    通过值$row['username']
    echo $row['username'], $row['password'];

     

    $result=mysqli_query($con,'select * from music');
    $row = mysqli_fetch_array($result,MYSQLI_NUM);    通过索引获取返回值
    echo $row[0], $row[1];

        $row = mysqli_fetch_assoc($result);      等同于 $row = mysqli_fetch_array($result,MYSQLI_ASSOC);

        

    $result=mysqli_query($con,'select * from music');
    $row = mysqli_num_rows($result);       取结果集的行数
    print_r($row);

        mysqli_affected_rows($con);      获取修改的数据数量

  • 相关阅读:
    一个简单的爬虫case2
    一个简单的爬虫case1
    Kick Start 2018-Round H-Problem C. Let Me Count The Ways
    Kick Start 2018-Round H-Problem B. Mural
    Kick Start 2018-Round H-Problem A. Big Buttons
    211. Add and Search Word
    HDU-1506 Largest Rectangle in a Histogram
    HDU-1236 排名
    HDU-1009 FatMouse' Trade
    HDU-1231 最大连续子序列
  • 原文地址:https://www.cnblogs.com/xiumumi/p/9841032.html
Copyright © 2011-2022 走看看