I am trying to establish a connection with mysql-5.1, but it shows errors like "could not connect" or when I change the hostname "Could not connect: No such file or directory".
My file reads like this
<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
printf("MySQL server version: %s\n", mysql_get_server_info());
?>
Tried changing mysql_connect to mysqli_connect. No difference.
1) The Mysql is running(as per the interface).
2) tried various rhc commands to restart the app, restart|reload the cartridge etc. - no errors while doing so."eg.Mysql-5.1 restart...done".
3) tried pinging the $OPENSHIFT_MYSQL_DB_HOST and it worked.
4) tried telneting the $OPENSHIFT_MYSQL_DB_HOST and it says connection established and some garbled text.
5) ps aux | grep "mysql" 4213 21721 0.0 0.0 103252 828 pts/0 S+ 10:56 0:00 grep mysql
6)mysql> status
/usr/bin/mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
Connection id: 4 Current database: Current user: xxxxxxxxxxxxx@xx.xx.xx.xx SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.1.73 Source distribution Protocol version: 10 Connection: xxxxxxxx-xxxxxxxxxxxxxxx.rhcloud.com via TCP/IP Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 TCP port: 50986 Uptime: 18 min 40 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 4 Queries per second avg: 0.3
I changed the code to
<?php
$mysqli = new mysqli('localhost', 'username', 'password', 'dbname');
/*
* This is the "official" OO way to do it,
* BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
*/
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
/*
* Use this instead of $connect_error if you need to ensure
* compatibility with PHP versions prior to 5.2.9 and 5.3.0.
*/
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
echo 'Success... ' . $mysqli->host_info . "\n";
$mysqli->close();
?>
again the same error.
Can somebody help me out? Even phpmyadmin code says "could not connect to mysql".
thanks Ganesh Kumar