I am trying to select data from a local database on my PC using PHP but i am getting this error when i run 127.0.0.1/test.php which is what the file is called.
error:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\test.php:11 Stack trace: #0 {main} thrown in
C:\xampp\htdocs\test.php on line 11
Here is my PHP script:
<?php
$servername = "Windows local servername";
$username = "Windows username";
$password = "windows password";
$dbname = "dbname";
// Create connection
$conn = mysql_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn){
die('error connecting to database');
}else{
mysql_select_db(dbname, $conn);
}
$sql = "SELECT UserId, UserEmail, UserPassword FROM User";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["UserId"]. " - UserEmail: " . $row["UserEmail"]. " " . $row["UserPassword"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
I have looked around online but i cant figure out what is wrong here. I can run a hello world php script and it works so i am assuming its a connection issue with the database but what have i missed here? Thanks
EXTRA:
i have:
