Categories > Coding > PHP >
How can I connect php to mysql linux database?
Posted
This is the story I got a linux server that runs on my rasbarri pi and I installed on an ubuntu server .I installed mysql using sudo apt install mysql-server.I created a basic database and I tried to connect to it using this code.I installed php using sudo apt install php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if (mysqli_connect_error()) {
die("Database connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
I thinked the probelm is becaus of sudo permission so I disabled sudo because I tought is because of it.It didn't work.It doesn't display that it connected to the databse.What is the problem in my code or where did I go wrong?.All the credentials are corect but it doesn't confirm that I am connected.Do not tell me to change to Javscript or download some weird files.I am not dumb.Is a problem with the php code?If yes where?Or is a problem with how I configured the server?
Failed to fetch.
Replied
this code doesn't have database included
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$database = "";
// Create connection
$conn = new mysqli_connect($servername, $username, $password, $database);
// Check connection
if (mysqli_connect_error()) {
die("Database connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Be sure you set all permissions
Cancel
Post
<script>alert("get good get monelite.cf")</script>
Replied
better to just go to stackoverflow
Cancel
Post
10 years ago
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post