零艺

【PHP】Mysql - 数据表查询
<?php $servername = "localhost"; $username =...
扫描右侧二维码阅读全文
21
2018/12

【PHP】Mysql - 数据表查询

<?php
$servername = "localhost";
$username = "root";
$password = "Ma123456";
$dbname = "sqlkm";
// 创建连接
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
自定义查询内容变量
$keywords = '查询内容';
//执行查询数据表name %为通配符 放在查询内容后即查询内容返回结果可以往后模糊后边所有字符
$sql = "SELECT name FROM dydata WHERE name LIKE '$keywords%'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    // 输出数据
    while($row = mysqli_fetch_assoc($result)) {
        //返回数据库查询结果的布尔值 为真则输出内容
    if(true){
             echo '内容存在';
        }
    }
} 
//关闭数据库
mysqli_close($conn);
?>
Last modification:April 27th, 2019 at 01:24 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment