混乱的PDO问题:无法通过套接字连接/拒绝访问/无法连接到服务器(共享主机) [英] Confusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)

查看:1171
本文介绍了混乱的PDO问题:无法通过套接字连接/拒绝访问/无法连接到服务器(共享主机)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题改变了,我会离开原来的问题,以防止错误的评论的答案像我之后,有人编辑他的问题,我回答:



所以我正在做一个(真的是跛行)共享主机已安装PDO,但它不工作。
使用默认参数

 <?php 
try {
$ dbh = new PDO ('mysql:host = localhost; dbname = THE_DB_NAME','THE_USER','THE_PASSWORD');
echo'Connected to database';
}
catch(PDOException $ e)
{
echo $ e-> getMessage();
}
?>

它会抛出此消息:

  SQLSTATE [HY000] [2002]无法通过套接字连接到本地MySQL服务器'/var/lib/mysql/mysql.sock'(2)



使用一个简单的mysql_connect,它可以工作。



套接字路径看起来是正确的phpinfo和此查询:

 显示诸如'socket'等变量; 

确认。



本地主机重定向到10.103.0.14(此数据来自mysql_get_host_info()和phpMyAdmin)



在PDO中,如果我将localhost替换为127.0.0.1,我会得到

  SQLSTATE [HY000] [2003]无法连接到'127.0.0.1'(111)上的MySQL服务器

如果我替换localhost 10.103.0.14:

 访问被拒绝用户'USER_NAME'@'10.103 .0.14'(使用密码:YES 

IP地址(127.0.0.1和10.103.0.14) with mysql_connect。



显然问题来自PDO连接。



有人知道这可以来从/或任何方式修复它?



某些服务器数据:



PHP版本:5.2 .10
您可以查看服务器的phpinfo: http://web.lerelaisinternet .com / abcd.php?v = 5
无命令行可能。
(我知道应该是技术支持者的工作,但他们的工作速度很慢)



感谢



上一个问题:



如何在共享主机上找到mysql.sock(需要很棘手的方法...)



所以今天的问题是:PDO连接不工作在共享主机上,它应该(它安装在服务器上)。
只是一个基本的PDO连接:

 <?php 
try {
$ dbh = new PDO('mysql:host = localhost; dbname = THE_DB_NAME','THE_USER','THE_PASSWORD');
echo'Connected to database';
}
catch(PDOException $ e)
{
echo $ e-> getMessage();
}
?>

会抛出此消息:

  SQLSTATE [HY000] [2002]无法通过套接字连接到本地MySQL服务器'/var/lib/mysql/mysql.sock'(2)



一个正常的mysql连接:

  mysql_connect localhost,THE_USER,THE_PWD)或die(mysql_error()); 
mysql_select_db(24DLJLRR1)或die(mysql_error());;
echo'已连接到数据库< br />';

工作正常。



找不到.sock。
我认为指定正确的地址应该工作,我尝试了一些经典的mysql路径,我在互联网上找到,没有成功。
phpinfo说这是在这个地址(/var/lib/mysql/mysql.sock)
(PHP版本是5.2.10)
你可以看到服务器的phpinfo: http://web.lerelaisinternet.com/abcd.php?v=5



所以我试图找出地狱是什么!
我试图查看phpMyAdmin接口,但我找不到信息,加上似乎phpMyAdmin连接到一个不同的服务器(它有一个不同的IP地址,并试图连接到它与php给出一个密码错误错误)。 mysql_connect也连接到这个地址,我认为它重定向到一个不同的服务器与一些内部密码/登录。



如果你有任何想法如何获得这个信息(提供商的技术支持是解决问题...已经1个月了...)。
也可能问题来自其他地方,但同样的东西在其他共享主机上工作...



PDO的需要是因为我使用Symfony框架与Doctrine为这个网站,和Doctrine插件需要PDO ...我不想从头开始重做网站!



感谢您的帮助! p>

解决方案

一年后,我发现了一个解决这个问题的方法:使用SQLite数据库。 PDO工作正常,但不是MySQL



**编辑**因为每个人都downvoting这:这解决了我的问题(我是OP)。我使用Doctrine,所以切换RDBMS是容易和快速。此外,该网站是一些自制CMS,与极少的交通,所以SQLite是好的。



我知道这不是一个真正的答案的问题,但如果有人在同一上下文:一个尴尬的共享主机,你不能改变与这个奇怪的PDO-MySQL错误 AND正在使用教义。这是一个解决方案。我可以删除这个答案,但如果我在OP的时候想到这个,我会节省了很多时间。


So the problem changed from what it was, i'll leave the original question below to prevent bad reviews on answers like I had after someone editing his question I answered :

So I am working on a (really lame) shared hosting which has PDO installed, but it doesn't work. With default parameters

<?php
try {
    $dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
    echo 'Connected to database';
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

it throws this message :

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

With a simple mysql_connect, it works.

And the socket path seems correct (both phpinfo and this query :

show variables like 'socket';

confirm.

Localhost redirects to 10.103.0.14 (this data comes from mysql_get_host_info() and in phpMyAdmin)

In the PDO, if i replace localhost by 127.0.0.1 i will get

SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111) 

And if i replace localhost by 10.103.0.14 :

Access denied for user 'USER_NAME'@'10.103.0.14' (using password: YES

Both IP adress (127.0.0.1 and 10.103.0.14) work with mysql_connect.

So apparently the problem comes from the PDO connection.

Does somebody knows where this could come from, or/and any way to fix it ?

Some server datas :

The PHP Version : 5.2.10 You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5 No command line possible. (i know it should be the tech suport's job, but they're reaaaaaly slow)

Thanks

Previous question :

How to find the mysql.sock on a shared host (tricky way needed...)

So today's problem is : The PDO connection doesn't work on a shared host, and it's supposed to (it's installed on the server). Just a basic PDO connection :

<?php
try {
    $dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
    echo 'Connected to database';
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

throws this message :

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

A regular mysql connection :

mysql_connect("localhost", "THE_USER", "THE_PWD") or die(mysql_error()); 
mysql_select_db("24DLJLRR1") or die(mysql_error());;
echo 'Connected to database <br/>';

works fine.

So apparently it cannot find the .sock. I think specifying the correct address should work, i tried some "classic" mysql path that I found on internet, without success. The phpinfo says it is at this adress (/var/lib/mysql/mysql.sock) (The PHP Version is 5.2.10) You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5

So i am trying to figure out where the hell it is !!! I tried to look in the phpMyAdmin interface, but i couldn't find the info, plus it seems that phpMyAdmin connects to a different server (it has a different IP adress, and trying to connect to it with php gives a "Wrong password" error). The mysql_connect also connects to this adress, i think it redirects to a different server with some internal password/login.

Well if you have any idea of how to obtain this info (the provider's technical support is "fixing the problem"... it's been 1 month...). Also maybe the problem comes from somewhere else, but the same stuff works on other shared hosts...

The need of PDO is because I use the Symfony framework with Doctrine for this website, and the Doctrine plugin needs PDO... I don't want to redo the website from scratch !

Thanks for your help !

解决方案

One year later, I found a solution for this issue : using a SQLite database. PDO worked fine, but not with MySQL

** EDIT ** as everyone is downvoting this: This solved my issue (I'm the OP). I was using Doctrine, so switching RDBMS was easy and quick. Also the website was some a home made CMS, with very few trafic, so SQLite was fine.

I know it's not a real "Answer" to the problem, but if someone is in the same context: a crappy shared hosting which you can't change with this weird PDO-MySQL bug AND is using doctrine. This IS a solution. I can delete this answer, but if I had thought of this at the time of the OP, I would have saved a lot of time.

这篇关于混乱的PDO问题:无法通过套接字连接/拒绝访问/无法连接到服务器(共享主机)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆