我有一个PHP脚本来访问远程mysql数据库中的数据。 脚本的重要部分是
$link = mysqli_connect("192.168.0.95", "user2", "passworduser2", "testDb", "3306")
OR die ('Could not connect to MySQL: '.mysql_error());
@mysql_select_db (DB_NAME)
OR die ('Could not select the database" '.mysql_error());
我从本地机器运行:
user1@webserver: php accessmysqldatabase.php
Could not select the database" Access denied for user 'user1'@'localhost' (using password: NO)
运行以下命令:
user1@webserver:~ $ mysql -u user2 -passworduser2 -h 192.168.0.95 testDb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 135
Server version: 5.5.59-0+deb8u1 (Raspbian)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
所以这让我感到困惑,因为在第二个例子中,我获得了与远程机器的连接,但在第一个(php)中它拒绝运行PHP脚本的用户,而不是用户进行连接并声称连接是localhost
我可以在远程计算机上使用phpmyadmin使用user2和密码登录,没有任何问题。
任何人都可以解释什么是错误的。
谢谢
答案 0 :(得分:-1)
我没有看到代码的res,但我认为你应该用你的表名替换const DB_NAME