//Connect to MySQL Database $host = 'localhost'; $username = 'root'; $password = ''; $dbname = 'exampleDB'; $conn = new mysqli($host, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully";
// Start the session session_start(); // Set session variables $_SESSION["username"] = "john_doe"; $_SESSION["email"] = "john_doe@gmail.com"; // Access session variables echo "Username is " . $_SESSION["username"] . ". Email is " . $_SESSION["email"] . ".";
// Define the API endpoint if($_SERVER["REQUEST_METHOD"] == "GET") { $data = array('message' => 'Hello World!'); header('Content-Type: application/json'); echo json_encode($data); }In conclusion, PHP is a versatile programming language that can be used to build a wide range of backend applications. By leveraging the many libraries and frameworks available, developers can create robust and scalable applications quickly and efficiently.