Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 已连接数据库,但select query不连接';不行?_Php_Database - Fatal编程技术网

Php 已连接数据库,但select query不连接';不行?

Php 已连接数据库,但select query不连接';不行?,php,database,Php,Database,我的数据库在dream主机上。而且它无法连接。 我的代码是 <?php $hostname = "mysql.demos.smartmobe.com"; // eg. mysql.yourdomain.com (unique) $username = "nayacinema"; // the username specified when setting-up the database $password = "****"; // the passwor

我的数据库在dream主机上。而且它无法连接。 我的代码是

<?php
    $hostname = "mysql.demos.smartmobe.com";   // eg. mysql.yourdomain.com (unique)
    $username = "nayacinema";   // the username specified when setting-up the database
    $password = "****";   // the password specified when setting-up the database
    $database = "nayacinema";   // the database name chosen when setting-up the database (unique)



    $con=mysqli_connect($hostname,$username,$password,$databse);
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }else{
        echo 'done';
    }
    $result = mysqli_query($con,"SELECT * FROM TblUsers");
    print_r($result);

    while($row = mysqli_fetch_array($result))
    {
        echo $row['FirstName'] . " " . $row['LastName'];
        echo "<br>";
    }

?>

可能是什么问题?

您有拼写错误

$con=mysqli\u connect($hostname、$username、$password、$database)

应该是

$con=mysqli\u connect($hostname、$username、$password、$database)


(数据库拼写错误)

您有拼写错误

$con=mysqli\u connect($hostname、$username、$password、$database)

应该是

$con=mysqli\u connect($hostname、$username、$password、$database)


(数据库拼写错误)

我已经测试了你的代码,没有连接。。由于拼写错误这里是正确的代码,我已经测试了我的本地机器

<?php
    $hostname = "localhost";   // eg. mysql.yourdomain.com (unique)
    $username = "root";   // the username specified when setting-up the database
    $password = "";   // the password specified when setting-up the database
    $database = "test";   // the database name chosen when setting-up the database (unique)



    $con=mysqli_connect($hostname,$username,$password,$database);
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }else{
        echo 'done';
    }
    $result = mysqli_query($con,"SELECT * FROM user");
    print_r($result);

    while($row = mysqli_fetch_array($result))
    {
        echo $row['id'] . " " . $row['user_name'];
        echo "<br>";
    }

?>


谢谢

我已经测试了你的代码没有连接。。由于拼写错误这里是正确的代码,我已经测试了我的本地机器

<?php
    $hostname = "localhost";   // eg. mysql.yourdomain.com (unique)
    $username = "root";   // the username specified when setting-up the database
    $password = "";   // the password specified when setting-up the database
    $database = "test";   // the database name chosen when setting-up the database (unique)



    $con=mysqli_connect($hostname,$username,$password,$database);
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }else{
        echo 'done';
    }
    $result = mysqli_query($con,"SELECT * FROM user");
    print_r($result);

    while($row = mysqli_fetch_array($result))
    {
        echo $row['id'] . " " . $row['user_name'];
        echo "<br>";
    }

?>


谢谢

你能给我们提供更多的代码吗?使用
echo mysqli_error($con)在mysqli\u查询之后
。它显示在执行查询时是否发现任何错误。您能提供更多的代码吗?使用
echo mysqli_error($con)在mysqli\u查询之后
。它显示执行查询时是否发现任何错误。这不是ansewr..这不是ansewr。。