0

I am install service MySQL to my PHP app on Bluemix and the error is on connection establish on this lines:

$con = mysql_connect("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv"); 
if (!$con){ 
    echo "Failed to connect to MySQL: " .mysql_error(); 
} 
mysql_select_db("d65a2b7e14b594d18a049ac918a4a8603",$con);
halfer
  • 19,824
  • 17
  • 99
  • 186
Adam
  • 21
  • 6
  • What is the text of the error? – halfer Jun 22 '15 at 09:42
  • @Marcin: is this not a PHP question? – halfer Jun 22 '15 at 09:42
  • the app stop on this line$con = mysql_connect("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv"); – Adam Jun 22 '15 at 10:05
  • so the error on connection !! i don't know why !! – Adam Jun 22 '15 at 10:06
  • 1
    Does it say, "error on connection"? Isn't there a message that is more specific? Is there anything in your MySQL error logs? – halfer Jun 22 '15 at 10:20
  • (Sorry Marcin. Not heard back from you to explain your edit, and this is quite plainly a PHP and MySQL question. Rolled back). – halfer Jun 22 '15 at 10:22
  • there are other php code after this line and the script stop when it reach to this line – Adam Jun 22 '15 at 10:30
  • **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Jun 22 '15 at 13:20
  • is the above syntax is error ? @Quentin – Adam Jun 22 '15 at 13:45
  • 1
    @ahmed — The `mysql_` functions have been deprecated (and will removed entirely from new versions of PHP) – Quentin Jun 22 '15 at 13:51
  • What is the error message you get? Are you sure thats the correct port and IP address? Are you sure the DB is accessible over TCP and not just by socket? – prodigitalson Jun 22 '15 at 18:08

3 Answers3

2

Quentin suggested to use mysqli instead of mysql_* as the latter is deprecated, i.e. try this:

 $mysqli = new mysqli("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv", "MYDB");
 $result = $mysqli->query("SELECT * from MYTABLE");
 $row = $result->fetch_assoc();
CharlesL
  • 942
  • 5
  • 14
  • Can you share the new code you're using and what the new error message is? – CharlesL Jun 23 '15 at 14:35
  • @ahmed: if an answer does not help, please try to explain more than "it does not work", since you have not supplied anything new to respond to. If you can explain at length what does not work, and any other new things you have tried, that often helps. – halfer Jun 25 '15 at 23:40
1

Create a folder

.bp-config/options.json in the parent folder

and add

{
    "PHP_EXTENSIONS": ["mysqli"]
}

in the options.json folder the sqli connect will work fine now

Deepak
  • 46
  • 5
0

Are you getting:

ERROR 2003 (HY000): Can't connect to MySQL server on '$host' (60).

A developer may have asked a similar question on developerWorks.

The answer seemed to be as follows:

  1. Downloaded the latest PHPMyAdmin(4.1.9)

  2. Created a BlueMix application using - cf push -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git ${myPhpAdminApp} . Note: the PHP build pack is used is PHP 5.4.26, which enables multi-byte support (it is different from the Heroku one in the BlueMix docs). This was necessary because the Heroku pack bundled PHP 5.3.27 which doesn't enable "multi-byte" character support by default. Multi-byte support is required to be enabled by PHPMyAdmin apparently.

  3. Added the existing MySQL service to this app. And picked the host, port, user, and password details from the VCAP_SERVICES environment variable.

  4. Copied config.sample.inc.php in the PHPMyAdmin to config.inc.php and added or modified the following lines in it based on the MySQL service VCAP_SERVICES details picked in previous step -

    $cfg['Servers'][$i]['host'] = 'host-ip-from-vcap_services';
    $cfg['Servers'][$i]['port'] = 'port-from-vcap_services';
    $cfg['Servers'][$i]['user'] = 'user-from-vcap_services';
    $cfg['Servers'][$i]['password'] = 'password-from-vcap_services';
    
  5. Pushed the updates using the above cf push ... again.

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
CharlesL
  • 942
  • 5
  • 14
  • I am firstly create the php application on bluemix then add MYSQL service and then : $con = mysql_connect("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv"); why this not work – Adam Jun 22 '15 at 16:28
  • help me please if you know – Adam Jun 22 '15 at 16:30