i get a blank page when using code to connect to a database using php even any print statement out side of the connection code is not printed only a blank page when running the following code
<?php
$link = new mysqli('localhost', 'root', '7610', 'sites');
if ($link) {
print "connected";
}
else { print "faild";}
?>
Try to use mysqli_connect() instead of mysqli()
Most People agree that PDO offers so much advantages over mysqli functions.... Why not try that Route? You would be glad you did... Here's what a PDO-based version would look like....
<?php
//DATABASE CONNECTION CONFIGURATION:
defined("HOST") or define("HOST", "localhost"); //REPLACE WITH YOUR DB-HOST
defined("DBASE") or define("DBASE", "sites"); //REPLACE WITH YOUR DB NAME
defined("USER") or define("USER", "root"); //REPLACE WITH YOUR DB-USER
defined("PASS") or define("PASS", "7610"); //REPLACE WITH YOUR DB-PASS
try {
$dbh = new PDO('mysql:host='.HOST.';dbname='. DBASE,USER,PASS);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
echo $e->getMessage();
}
if($dbh instanceof PDO){
print "The Coast is clear...";
}else{
print "We have a Huge Storm on our hands.... BAIL ;-)";
}
// FROM HERE ON, YOU COULD START USING $dbh AS YOUR PDO OBJECT...
// FOR EXAMPLE YOU COULD DO A SELECT LIKE SO:
$sql = 'SELECT u.* FROM user AS u';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
var_dump($result);