PHP and MySQL connections to server

December 19, 2023 · Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

1. Prerequisites:

  • Web server: A web server such as Apache or Nginx is required to execute PHP code.
  • MySQL server: Install and configure MySQL server.
  • MySQL credentials: Keep the database username, password, and hostname readily available.

2. Connection Script

Create a PHP file (e.g., connect.php) with the following code:

<?php

// Database credentials
$hostname = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";

// Create connection

$conn = new mysqli($hostname, $username, $password, $dbname);

?>

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion