mercredi 28 janvier 2015

php connect to mysql


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?



Aucun commentaire:

Enregistrer un commentaire