All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

How To Connect To phpMyAdmin Database In PHP

Last Updated : Mar 11, 2024

How To Connect To phpMyAdmin Database In PHP

In this article we will show you the solution of how to connect to phpMyAdmin database in php, to manage MySQL databases, you can use phpMyAdmin, a GUI-based application.

A query can be performed on a database and table that have been manually created. Any server can run it and it has a web-based interface.

Due to its web-based nature, it can be accessed from any computer.

SQL queries can be executed using the user interface provided by phpMyAdmin.

In MySQL Console, we cannot copy and paste queries, but we can paste them into SQL to test our output. The MySQL console requires a query every time.

Step By Step Guide On How To Connect To phpMyAdmin Database In PHP :-

  1. Follow the instructions below to download the latest version of phpMyAdmin from https://www.phpmyadmin.net/. Start downloading by clicking the download button.
  2. This will open a pop-up window. The next step is to click the Close button.
  3. For easy access on the browser, right-click the downloaded file and select Extract here. Rename the folder to PhpMyAdmin.
  4. Extract all the files of phpMyAdmin from the downloaded location and move them to C:/Apache/htdocs. Alternatively, we can extract files directly from the Apache htdocs folder.
  5. You can open the httpd file by going into the Apache conf folder on the C drive.
  6. Press the Ctrl+F key and find index.html written in the file. Now, replace the .html extension with .php and save the file.
  7. Using the services of your computer system, you can check whether the Apache server is running. For the phpMyAdmin interface to open on the browser, the Apache server must be running.
  8. Now open the browser and type http://localhost/phpmyadmin/. phpMyAdmin will start running in the browser.
  9. Click on New (1) to create a database and enter the database name in Create database (2) field and then click on Create (3) button. We can create any number of databases.
  10. Enter the table name, and the number of columns, and click on Go. A message will show that the table is created successfully.
  11. Now enter the field name, type, size, and any constraint here and save it.
  12. The table is created successfully. We can make changes to the table from here.
  13. Database creation using coding with phpMyAdmin
  14. We can create the database and tables using phpMyAdmin graphical user interface as well as with coding in PHP.
<?php
   $servername = "localhost";
    $username = "root"; //default user name is root
    $password = ""; //default password is blank
    $conn = mysqli_connect($servername, $username, $password);
    if(!$conn)
        die("Connection failed".mysqli_connect_error());
    else
         //echo "Successfully connected with database";
    $query = "CREATE DATABASE newDB";
if (mysqli_query($conn, $query)) {
     echo "Database created successfully with the name newDB";
  } else {
      echo "Error creating database: ". mysqli_error($conn);
   }
    mysqli_close($conn);
?>
//Database created successfully with the name new DB.
  1. The short tags start with "<?" and end with "?>". Short style tags are only available when they are enabled in the php.ini configuration file on servers.
  2. The $_SERVER array contains information about headers, paths, and script locations. Array entries are created by the web server. There is no guarantee that each web server will provide similar information; instead, some servers may provide information that is not listed here, or exclude information that is listed here.
  3. The HTML element represents the root of an HTML with the version information in the document type declaration.
  4. The input element, having the "password" value in its type attribute, represents a field for passwords.
  5. The connect() / mysqli_connect() function opens a new connection to the MySQL server.
  6. Then we use if and else statements for creating query statements.
  7. It returns an object which represents the MySQL connection. If the connection failed then it returns FALSE.
  8. The echo() function is not actually a function, so you are not required to use parentheses with it.
  9. Then we use query statements for insert, update, and delete statement
  10. Then we use MySQL close statement.

Conclusion :-

GUI phpMyAdmin coming for handling CRUD operations i.e insert(create), update, delete, and select(read) records from tables. This interface is browser-based and very helpful, easy to use for creating and managing the PhpMyAdmin database in a table(column, row).

PHP is the most popular server-side programming language. It is used more than 70% in comparison to other website development languages.

I hope this article on how to connect to phpMyAdmin database in php helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Dikshita

Passionate Electronics and Communication Engineering student with expertise in web development (HTML, CSS, JS,PHP, Bootstrap, React.js) and content writing. Eager problem solver and tech enthusiast, adept at creating engaging web experiences.

Follow Dikshita On Linkedin 🡪