Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)
    primarykey
    data
    text
    <p>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 :</p> <p>So I am working on a (really lame) shared hosting which has PDO installed, but it doesn't work. With default parameters</p> <pre><code>&lt;?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-&gt;getMessage(); } ?&gt; </code></pre> <p>it throws this message :</p> <pre><code>SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) </code></pre> <p>With a simple mysql_connect, it works.</p> <p>And the socket path seems correct (both phpinfo and this query :</p> <pre><code>show variables like 'socket'; </code></pre> <p>confirm.</p> <p>Localhost redirects to 10.103.0.14 (this data comes from mysql_get_host_info() and in phpMyAdmin)</p> <p>In the PDO, if i replace localhost by 127.0.0.1 i will get</p> <pre><code>SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111) </code></pre> <p>And if i replace localhost by 10.103.0.14 :</p> <pre><code>Access denied for user 'USER_NAME'@'10.103.0.14' (using password: YES </code></pre> <p>Both IP adress (127.0.0.1 and 10.103.0.14) work with mysql_connect.</p> <p>So apparently the problem comes from the PDO connection.</p> <p>Does somebody knows where this could come from, or/and any way to fix it ?</p> <p>Some server datas :</p> <p>The PHP Version : 5.2.10 You can see the server's phpinfo : <a href="http://web.lerelaisinternet.com/abcd.php?v=5" rel="noreferrer">http://web.lerelaisinternet.com/abcd.php?v=5</a> No command line possible. (i know it should be the tech suport's job, but they're reaaaaaly slow)</p> <p>Thanks</p> <p>Previous question :</p> <h2>How to find the mysql.sock on a shared host (tricky way needed...)</h2> <p>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 :</p> <pre><code>&lt;?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-&gt;getMessage(); } ?&gt; </code></pre> <p>throws this message :</p> <pre><code>SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) </code></pre> <p>A regular mysql connection :</p> <pre><code>mysql_connect("localhost", "THE_USER", "THE_PWD") or die(mysql_error()); mysql_select_db("24DLJLRR1") or die(mysql_error());; echo 'Connected to database &lt;br/&gt;'; </code></pre> <p>works fine.</p> <p>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 : <a href="http://web.lerelaisinternet.com/abcd.php?v=5" rel="noreferrer">http://web.lerelaisinternet.com/abcd.php?v=5</a></p> <p>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.</p> <p>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...</p> <p>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 !</p> <p>Thanks for your help !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COIt could be that the socket exists, but you don't have the necessary rights to access it. Anyway, isn't this a question for your provider's tech support?
      singulars
    2. COI guess it's there job !they're too lame, we've been waiting for more than a month, plus it's in France, it takes 30 minutes to get the right person. The problem is that it's an important customer and we have to ship... (the website is working on a mirror right now, but we the customer wants it on his host and it belongs to the french telecom company, so we can't say it's lame). Moreover we can not talk directly to the server tech support. So how come i wouldn't have the rights to access it ? I mean if PDO is installed and i can connect by mysql_connect i should have them no ?
      singulars
    3. COas far as i understand it, you are out of luck. the maped localhost to a diffrent ip. but it seems the mysql server itself only allow access from localhost (which in their case resolves to your 10.103.0.14). pdo seems to use sockets if the host is localhost. (see php.net documentation, pdo - connection second comment) but why mysql_connect works with 127.0.0.1 is very strange. in this case pdo connect with host=127.0.0.1 should work too.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload