我一直试图找到一种解决方法,以便在访问我的index.php文件时找到mysql错误消息,代码如下:
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /Applications/XAMPP/xamppfiles/htdocs/cms/includes/navigation.php on line 24
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/cms/includes/navigation.php on line 26
对于我的生活,我无法弄清楚我在这里做错了什么,因为它在我使用静态链接时起作用,但是在测试动态链接时,它只会变得很糟糕。
以下是我用于导航包含文件夹的navigation.php文件的代码:
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<?php
$query = "SELECT * FROM categories";
$please_work = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($please_work)){
$cat_title = $row['cat_title'];
echo "<li><a href='#'>{$cat_title}</a></li>";
}
?>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
当然我的db.php文件也位于我的包含文件夹中:
<?php
$db['db_host'] = "localhost";
$db['db_user'] = "root";
$db['db_pass'] = "";
$db['db_name'] = "cms";
foreach($db as $key => $value){
define(strtoupper($key), $value);
}
$connection = mysql_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if($connection){
echo "We are connected";
}
?>
我不太需要发布我的index.php,因为我知道错误并非来自那里,因为静态内容在使用时正在工作,这意味着include功能正在运行。
有人可以让我免于长期头痛吗?
谢谢,
CB
答案 0 :(得分:1)
您正在混合[ProtoContract]
class SubMessageRepresentations
{
[ProtoMember(5, DataFormat = DataFormat.Default)]
public SubObject lengthPrefixedObject;
[ProtoMember(6, DataFormat = DataFormat.Group)]
public SubObject groupObject;
}
[ProtoContract(ImplicitFields=ImplicitFields.AllFields)]
class SubObject { public int x; }
using (var stream = new MemoryStream()) {
_pbModel.Serialize(
stream, new SubMessageRepresentations {
lengthPrefixedObject = new SubObject { x = 0x22 },
groupObject = new SubObject { x = 0x44 }
});
byte[] buf = stream.GetBuffer();
for (int i = 0; i < stream.Length; i++)
Console.Write("{0:X2} ", buf[i]);
}
和mysql_*
个功能。您应该始终使用mysqli_*
。
所以,你需要改变这个:
mysqli_*
到此:
$connection = mysql_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);