0

I'm trying to deploy a php web application on bluemix. So I have bound a clearDB mysql service to my application. The vcap_service variable are provided to me. but when I use those variable to perform simple sql query, the application page does nothing, while same code is doing well with xamp localhost. please help me.

here is the code :

<?php
$servername = "us-cdbr-iron-east-02.cleardb.net";
$username = "b23807********";
$password = "********";
$dbname = "ad_70723170af1****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// sql to create table
$sql = "CREATE TABLE flybird (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";

if ($conn->query($sql) === TRUE) {
    echo "Table flybird created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

The following error is showing: Got error 'PHP message: PHP Fatal error: Class 'mysqli' not found in /home/vcap/app/htdocs/table.php on line 8\n.

Nick
  • 1,417
  • 1
  • 14
  • 21
Sahil S.
  • 59
  • 7

3 Answers3

2

There is an issue with the php buildpack, you need to explicitly add the mysqli function in your application.

Create a file called .bp-config/options.json. You can customize the php buildpack extensions, check this out for more info.

The contents should contain the following.

{
    "PHP_EXTENSIONS": ["mysqli"]
}
Jeff Sloyer
  • 4,899
  • 1
  • 24
  • 48
0

you should specify mysqli dependency on composer.json config.

{"require": { "ext-mysqli": "*" } }

v.bontempi
  • 1,562
  • 1
  • 9
  • 10
-2

I think you need to explicitly add the mysqli function in your application

You have to enable the library in .bp-config/options.json file. Like the example below

EX:

{ "PHP_EXTENSIONS": ["mysqli"] }

If you don't have this file in your aplication just create it, add the extension and push it to your Bluemix app. (link)

Check this page on developerworks for more information , i think it is the same issue you are having (link)