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);//关闭连接

    ?>

  • 相关阅读:
    准备ing
    六月的最后一星期
    对象及其内存管理 笔记
    数组及其内存管理 笔记
    笔记
    搜狐 云端服务组实习面试小记
    leetcode之Binary Tree Level Order Traversal
    数据库01-范式总结
    Tour UVa 1347 (DAG)
    Directed Acyclic Graph DAG(有向无环图)上的DP
  • 原文地址:https://www.cnblogs.com/peipeiyu/p/10493105.html
Copyright © 2011-2022 走看看