Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

在php中连接数据库query数据返回值为空?

<?php
    $user = '...';
    $password = '...';
    $db = '...';
    $host = '...';
    $port = ....;
    $link = mysqli_init();
    $success = mysqli_real_connect(
       $link,
       $host,
       $user,
       $password,
       $db,
       $port
    );
//     mysqli_query($success, "set names utf8");
    $sql = "SELECT * FROM nodes";
    $nodesPHP = mysqli_query($success, $sql);
    $err = mysqli_connect_error();
    echo $err;
    echo $nodesPHP;
    echo $success;
?>

因为之前php文件一直得不到sql数据所以单独写了一个php用来测试,
发现页面上只有"echo $success"打印的"1", err和nodesPHP都为"", 但是实际上database里应该是有数据的,权限也检查过了,一直找不到问题出在哪里


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<?php

$nodesPHP=mysqli_query($link,$sql);

msyqli_query 的第一个参数,应该是一个mysqli 的链接句柄啊.你传入一个 bool 值搞啥?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...