MySQL connect to domain rather than localhost
I have read a bunch of things, and tried a bunch of things, but we have 2 linodes, and we are trying to do a simple mysql connect from one to another.
I can connect to the mysql from my shell on the other linode, but if I try to use PHP to connect, I am unable to connect.
I know it's not a firewall issue, I can turn that off and still no difference.
As a side note, I can also connect to the database on the same linode using 'localhost', but I can not connect to the same database using it's domain name?
So…. I can connect to localhost, but not when I use domain to the same server, and this leads me to not being able to connect to my other servers remotely. (I do have grant access to them setup AND I can connect to them using the shell… just not through PHP)
any suggestions?
1 Reply
I'm not an expert on MySQL or PHP, but I think I may have found some information that can help. It seems like there may need to be adjustments made to your MySQL database in order to get a PHP connection to work. There are two different tools that can be used to prep a MySQL DB for PHP connection: MySQLi extension and PDO.
MySQLi Extension
This is an extension that provides improved functionality and persistent connection support for MySQL DB. It includes PHP libraries that need to be installed for the MySQL DB to understand your connection request. You can find instructions on how to install the MySQLi Extension in this link: MySQLi Install.
PDO
PHP Data Objects is another extension that provides a framework for accessing a database using the PHP language. PDO adds a layer of uniformity to query functions for a variety of databases including MySQL. This guide provides detailed directions on how to install PDO.
It is likely that the issues you're seeing are due to the need for either the MySQLi or PDO extensions. For further reference, I'd also check out this site that provides screenshots of some scripts you'll have to put together, W3SchoolsPHP. Hopefully this will fix your PHP connectivity issue. Good luck!