简体   繁体   English

为什么我可以使用本地主机连接到托管网站数据库?

[英]Why can I connect to my hosted website database using localhost?

This might be a stupid question but why am i using local host if my site is being hosted with rackspace? 这可能是一个愚蠢的问题,但是如果我的网站由机架空间托管,为什么我要使用本地主机?

$db_host = "localhost";
$db_username = "*****";
$db_pass = "********";
$db_name = "lds";


$link = mysql_connect('localhost','*****','*********');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
echo 'Connected successfully';
mysql_close($link);

It appears to be getting a connection because I'm successfully echoing 'Connected successfully'. 似乎正在建立连接,因为我成功地回显了“已成功连接”。

Maybe something is terribly wrong because i noticed when i took out localhost from both mysql_connect function and from the db_host variable... it still says connected successfully. 也许有些错误,因为我注意到当我从mysql_connect函数和db_host变量中取出localhost时,它仍然表示连接成功。

Would that be because i've already wired the ftp connections up in my IDE? 那是因为我已经在我的IDE中连接了ftp连接吗?

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance. 提前致谢。

Your database server is running locally to the remote machine, where you are executing your PHP script(s). 数据库服务器在远程计算机本地运行,在远程计算机上执行PHP脚本。 To your script the database appears to be localhost even though the web server and database server are remote relative to you. 对于您的脚本,即使Web服务器和数据库服务器相对于您而言是远程的,数据库也似乎是localhost

Per the documentation for mysql_connect : 根据mysql_connect的文档:

If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. 如果未定义PHP指令mysql.default_host(默认),则默认值为“ localhost:3306”。

This would seem to indicate that if no value for the database server is provided, the default is used. 这似乎表明,如果未提供数据库服务器的值,则使用默认值。 Also note that the documentation also states that this function is deprecated in PHP 5.5.0. 另请注意,文档还指出此功能在PHP 5.5.0中已弃用

See instead: http://php.net/mysqli and http://php.net/pdo 改为查看: http : //php.net/mysqlihttp://php.net/pdo

只要您的php我们的服务器和MySQL数据库服务器在同一台机器上,本地主机就可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我不能使用 PHP 连接到我的 mssql 数据库? - Why can't I connect to my mssql database using PHP? 为什么我不能在我的托管域中使用 swiftmailer 发送邮件,但是从我的本地主机服务器发送邮件时没有错误 - Why can I not send mail with swiftmailer in my hosted domain but there is no error when sending it from my localhost server 我无法使用php连接到本地主机 - I can't connect to my localhost using php 我无法使用xampp访问本地主机中的数据库 - I can't access my database in localhost using xampp 为什么我无法通过使用Ajax的查询连接到数据库? - Why i can't connect to database using my query using ajax? 如何将托管的php网站连接到本地服务器上的SQL Server数据库 - how to connect my hosted php website to SQL Server Database on my local server 我无法将我的数据库表连接到我的网站以进行注册和登录 - I can't connect my database table to my website in order to register and sign in 无法连接到本地主机上的数据库 - Can't connect to database on localhost 为什么我不能使用PHP Slim框架连接到数据库? - Why can't I connect to database using PHP Slim framework? 如何使用本地IP地址而不是localhost访问数据库mysql服务器 - How can I access my database mysql server using my local ip address instead of using localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM