所以,我需要一种方法来找到名为的 MYSQL 数据库
website_side
有没有办法为自己找到一个 IP 位置,该位置将指向保存登录表的系统? 喜欢
192.168.1.190:3306/website_side
最佳答案
由于 MySQL 运行在访问它的同一台计算机上,因此可以从连接器使用 localhost
来访问数据库。或者,如果您想要实际的 IP 地址,也可以使用 127.0.0.1
(但是在这种情况下主要使用 localhost)。
因此,对于您的 PHP 代码,您将执行类似的操作(假设定义了所有其他值):
// .. Other defines up here ..
define("DB_SERVER","localhost");
// .. Your connector class ..
function MySQLDB(){
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
$this->num_members = -1;
if(TRACK_VISITORS){
$this->calcNumActiveUsers();
$this->calcNumActiveGuests();
}
}
请注意,以这种方式定义变量对于 PHP 来说有点不常见。相反,诸如 $DB_SERVER
和 $DB_SERVER="localhost";
之类的内容更为常见。
关于php - 如何从 MYSQL 数据库获取登录系统的 IP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19338858/