为什么我的代码返回此错误:mysql_query() access denied for user ''@'localhost' (using password no) [英] Why does my code return this error: mysql_query() access denied for user ''@'localhost' (using password no)

查看:49
本文介绍了为什么我的代码返回此错误:mysql_query() access denied for user ''@'localhost' (using password no)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="items"><ul><li><?php echo $msg[$lang]["gtd"];?><div class="text"><强><?php$result = mysql_query("SELECT id FROM games WHERE `starttime` > ".(time()-86400));回声 mysql_num_rows($result);?></strong>

此代码的第 8 行返回错误:

mysql_query() 用户 ''@'localhost' 访问被拒绝(使用密码 no)".

解决方案

https://stackoverflow.com/search?q=mysql_query%28%29+access+denied+for+user+%40%27localhost%27

这在 SO 和 谷歌.

您似乎根本没有连接到数据库.包括以下内容(当然,使用您的凭据填充函数参数):

$connection = mysql_connect('localhost', 'db_username', 'db_password')或者 die('连接问题:' .mysql_error());mysql_select_db('your_database', $connection);

</div>
    <div class="items">
        <ul>
            <li>
            <?php echo $msg[$lang]["gtd"]; ?>
                <div class="text">
                    <strong>
                    <?php
                        $result = mysql_query("SELECT id FROM games WHERE `starttime` > ".(time()-86400));
                        echo mysql_num_rows($result);
                    ?></strong>
                </div>
            </li>

Line 8 of this code returns the error:

mysql_query() access denied for user ''@'localhost' (using password no)". 

解决方案

https://stackoverflow.com/search?q=mysql_query%28%29+access+denied+for+user+%40%27localhost%27

This is an extremely popular issue on both SO, as well as Google.

You don't appear to have connected to the database at all. Include the following (populating the function arguments with your credentials, of course):

$connection = mysql_connect('localhost', 'db_username', 'db_password')
    or die('connection problem:' . mysql_error());

mysql_select_db('your_database', $connection);

这篇关于为什么我的代码返回此错误:mysql_query() access denied for user ''@'localhost' (using password no)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆