Php 已连接数据库,但select query不连接';不行?
我的数据库在dream主机上。而且它无法连接。 我的代码是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
<?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。。