0

I am using Trisquel 7.0 LTS and installed php5 and php5-mysql. All php scripts working properly.(I used to write my-learning scripts in /var/www/html/xyz.php and all is working by http://localhost/xyz.phpproperly) Now I want to create database using php and hence I am visiting w3schools' tutorial.

I've written following code in data.php under /var/www/html/:

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?> 

But When I open http://localhost/data.php, blank page appeared!

I Also tried:

// Check connection
if (mysqli_connect_error()) {
    die("Database connection failed: " . mysqli_connect_error());
}

What I'm missing?

1 Answer 1

0

Oh! I am missing some packages which requires for installation of MySQL with PHP5. Information provided on community page at Ubuntu Documentation helps me:

Required packages are :

mysql-server libapache2-mod-auth-mysql php5-mysql

And I had installed only php5-mysql so I've installed all packages by following command:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

And Now php displays "Connected successfully"!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .