首页 > 数据库技术 > 详细

mysqli链接数据库

时间:2019-03-07 22:40:46      阅读:191      评论:0      收藏:0      [点我收藏+]

<?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.\n" . mysqli_content_error());//诊断连接错误
}

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

if (!$result) {
    die("could not to the database\n" . 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 . "\n";

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

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

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

?>

mysqli链接数据库

原文:https://www.cnblogs.com/peipeiyu/p/10493105.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!