I'm trying to take and get data from a database to a website using php. When I'm trying to connect I'm using this code:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'test';
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_errno) echo "failed to connect to database";
?>
but upon trying to open the php file I recieve this on firefox:
connect_errno) echo "failed to connect to database"; ?> (on firefox)
and this on opera/chrome:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'test';
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_errno) echo "failed to connect to database";
?>
I have also tried loading it with internet explorer but it simply tries to save it again. I'm not understanding what I am doing wrong.
For extra detail I am trying to do this through xampp using phpmyadmin.
Okay, I fixed it just incase anyone looks back at this essentially the issue was my misunderstanding of the instruction 'open the php'. I was opening it directly to the browser, I needed to open it via localhost. so localhost/connect.php rather than just opening connect.php to the browser.