Categories > Coding > PHP >

How can I connect php to mysql linux database?


Posts: 29

Threads: 18

Joined: Oct, 2021

Reputation: 0

  • 0

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?

Blueless

2000's 3D

Posts: 178

Threads: 19

Joined: Dec, 2021

Reputation: 3

  • 0

Replied

https://www.youtube.com/watch?v=VidqoMsdySs maybe this can help you

Posts: 11

Threads: 2

Joined: Jan, 2022

Reputation: -31

  • 0

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

<script>alert("get good get monelite.cf")</script>

Posts: 155

Threads: 16

Joined: Jul, 2021

Reputation: 4

  • 0

Replied

better to just go to stackoverflow

hi how are you



Users viewing this thread:


( Members: 0, Guests: 1, Total: 1 )