-1

I am coming from a mysql_select_db background and need to get up on mysqli.

I am having trouble connecting with mysqli to my database at Media Temple. I have confirmed that the connection info is correct by connecting via php myAdmin on the MT server. (000000 is substituted below).

my code:

$mysqli = new mysqli("internal-db.000000.gridserver.com", "db000000", "password", "db000000_dbName");
$result = $mysqli->query("select * from 'users'"); 
$row = $result->fetch_assoc();
echo htmlentities($row['fieldName']);

I receive the following errors:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on 'internal-db.000000.gridserver.com' (61) 

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli //this is because of the bad connection

Fatal error: Call to a member function fetch_assoc() on a non-object //this is because of the bad connection

Here's a link on MT's site: http://kb.mediatemple.net/questions/4/Why+can%27t+I+connect+to+my+MySQL+database+from+PHP%3F#gs

What am I missing here? Thanks for reading.

JWC_WDC
  • 77
  • 2
  • 11
  • so if you do the connect using mysql instead of mysqli - it works?! – herrjeh42 Mar 27 '13 at 23:14
  • And: how have you confirmed that the settings are all right - did you connect to the mysql server using the mysqlclient in the shell? – herrjeh42 Mar 27 '13 at 23:16
  • 1
    can you connect to the server via ssh and run " mysql --host=localhost --user=myname --password=mypass mydb" adapted to your settings - just to make sure that it works, e.g. that they do not skipped e.g. the port in the manual? – herrjeh42 Mar 27 '13 at 23:28
  • testing via ssh is up next. – JWC_WDC Mar 27 '13 at 23:32

2 Answers2

1

the server adress haves this format?

internal-db.000000.gridserver.com?

if you do a ping on internal-db.000000.gridserver.com do you get a IP?

Acuao
  • 671
  • 4
  • 15
  • Ping comes back with nothing, that address seems to be what they want, per edit I just posted. – JWC_WDC Mar 27 '13 at 23:10
  • does you passwords contains special characters like `" or '`? Only the 1st error is interresting, because other errors are due to the first – Acuao Mar 27 '13 at 23:14
  • it seems to be ok, exclamation point doesn't affects php's string declarations – Acuao Mar 27 '13 at 23:28
0

Your connection is not being established for the host. If this script is running on the same host as the database, just use localhost rather than the fully qualified host name. The error message will be different for a user name or remote access permission problem. This looks more like a networking (firewall) type issue.

  • the hoster shows some exemples and they use the subdomain, so i imagine they opened the firewall.. – Acuao Mar 27 '13 at 23:25
  • 1
    Potential issue if your not internal/local from MT site: For external connections, use external-db.s00000.gridserver.com instead and make sure your IP address has been added to the list of allowed external IPs. Click here for details. – GhostScript Mar 27 '13 at 23:35
  • mmh yeah interresting... @JWC_WDC did you simply tryed `localhost` ? – Acuao Mar 27 '13 at 23:40
  • Yep I did try localhost, I'll try the external/IP next as well. – JWC_WDC Mar 27 '13 at 23:41
  • finally found (61) means: ECONNREFUSED ("Connection refused"). – GhostScript Mar 27 '13 at 23:45