zoukankan      html  css  js  c++  java
  • mysqli链接数据库

    <?php


    $uid = $_GET['uid'];

    $host = 'localhost';
    $database = 'test';
    $username = 'root';
    $password = '123456789';
    $selectName = 'harry';//要查找的用户名,一般是用户输入的信息
    $insertName = 'testname';

    $connection = mysqli_connect($host, $username, $password,$database);//连接到数据库
    if (!$connection) {
        die("could not connect to the database. " . mysqli_content_error());//诊断连接错误
    }

    $query = "select * from tp_users where uid =" . $uid;//构建查询语句
    $result = mysqli_query($connection,$query);//执行查询

    if (!$result) {
        die("could not to the database " . mysqli_content_error());
    }

    while ($row = mysqli_fetch_row($result)) {
        print_r($row);
    }

    //添加记录
    // $insertSql = "insert into tp_users(name, age) values('$insertName', 18)";
    // $result = mysqli_query($connection,$insertSql);
    // echo $result . " ";

    //更新记录
    // $updateSql = "update user set uid = 3 where name=2";
    // $result = mysqli_query($connection,$updateSql);
    // echo $result . " ";

    //删除记录
    // $deleteSql = "delete from user where uid = 3";
    // $result = mysqli_query($connection,$deleteSql);
    // echo $result . " ";

    mysqli_close($connection);//关闭连接

    ?>

  • 相关阅读:
    论语心得
    水果总结
    欢乐颂
    大牌驾到
    Excel补全日期(日期按顺序补全)
    c语言define和typedef区别和使用
    c语言寄存器变量
    c语言伪常量const理解
    c语言静态断言-定义自己的静态断言
    c语言静态断言
  • 原文地址:https://www.cnblogs.com/peipeiyu/p/10493105.html
Copyright © 2011-2022 走看看