Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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"!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.