php mysqli_query结果没有

前端之家收集整理的这篇文章主要介绍了php mysqli_query结果没有前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参见英文答案 > How do I get PHP errors to display?                                    24个
我试图使用MysqLi_query从表中获取数据.
当我使用以下命令时,它可以正常工作:

$hostname = "********";
$username = "*******";
$password = "********";
$databaseName = "**************";
$dbConnected = MysqLi_connect($hostname,$username,$password,$databaseName);

当我尝试包含上述代码文件包括(‘../ htconfig / dbConfig.PHP’);然后我没有得到任何结果:

……“0结果”

PHP

include('../htconfig/dbConfig.PHP');
$dbConnected = MysqLi_connect($db['hostname'],$db['username'],$db['password'],$db['databaseName']); 

if(!$dbConnected) {
    die('Connect Error (' . MysqLi_connect_errno() . ') '
            . MysqLi_connect_error());
}
echo 'Success... ' . MysqLi_get_host_info($dbConnected) . "\n". "MysqLi_set_charset($dbConnected,"utf8");

$tPerson_sqlselect = "SELECT  ";
$tPerson_sqlselect .= "ID,Salutation,FirstName,LastName,CompanyID ";    
$tPerson_sqlselect .= "FROM ";
$tPerson_sqlselect .= "tPerson ";           

$result = MysqLi_query($dbConnected,$tPerson_sqlselect);

if (MysqLi_num_rows($result) > 0) {
// output data of each row
while($row = MysqLi_fetch_assoc($result)) {
    echo "Salutation: ".$row["Salutation"]. "-FirstName: ".$row["FirstName"]." ".$row["LastName"]."  -CompanyID: ".$row["CompanyID"]. "MysqLi_close($dbConnected);
?>

我找不到我的错误..
请帮忙 !

dbConfig.PHP文件

PHP
$db = array(
'hostname' => '*****','username' => '*****','password' => '*****','database' => '*****',); 
?>
最佳答案
如果您仍在使用相同的变量名,那么$dbConnected应该是这样的:

include('../htconfig/dbConfig.PHP');
$dbConnected = MysqLi_connect($hostname,$databaseName);

如果你想要它是$db [‘field’]那么你的../htconfig/dbConfig.PHP应该是这样的:
    

$db = array('hostname' => 'xxxx','username' => 'xxxx','password' => 'xxxx','databaseName' => 'xxxx');

编辑:
你在dbConfig.PHP中的数组说’数据库’,但你在$dbConnected MysqLi_connect函数中使用了’databaseName’?

原文链接:https://www.f2er.com/mysql/433238.html

猜你在找的MySQL相关文章