DEV Community

Opuama Lucky
Opuama Lucky

Posted on

CREATE MYSQL CONNECTION IN PHP

Introduction

XAMPP is the most popular software package which is used to set up a PHP development environment for web services by providing all the required software components.XAMPP provides easy transition from local server to live server. XAMPP is a AMP stack which stands for Cross platform, Apache, MySQL, PHP, perl with some additional administrative software tools such as PHPMyAdmin (for database access).

Steps to Download and Install Xampp

XAMPP is a completely free, easy to install Apache distribution.

  • In the web browser, visit Apache Friends and download XAMPP installer.
  • click on the required version and bit on your system Alt Text download and install.
  • Uncheck the Learn more about bitnami option and click Next button.
  • Click the Allow access button to allow the XAMPP modules from the Windows firewall.
  • After the installation process, click the Finish button of the XAMPP Setup wizard.
  • Now the XAMPP icon is clearly visible on the right side of start menu. Show or Hide can be set by using the control panel by clicking on the icon. To start Apache and MySql, just click on the Start button on the control panel. Alt Text
  • Open your web browser and check whether the XAMPP service has properly installed or not. Type in the >URL: http://localhost. If you are able to see the default page for XAMPP, you have successfully installed your XAMPP Server. Alt Text

Connection with php

<?php $conn = mysqli_connect("localhost","root","");
?>
Enter fullscreen mode Exit fullscreen mode
                     OR
Enter fullscreen mode Exit fullscreen mode
<?php
$localhost='localhost';
$root='root';
$pass='';
mysqli_connect($localhost,$root,$pass);
?>
Enter fullscreen mode Exit fullscreen mode

Connection With Database

If you are using database here are the connections.

  1. click on xampp and start Apache and MySQL.
  2. open the htdocs folder. You can find it under the XAMPP folder in your local disk (C: or D:) or any local disk name on your sysytem. In this htdocs folder, we will create a new folder named our database 'First' to store our web files. XAMPP will use this 'First' folder to execute and run the PHP web pages or website.
  3. Type >localhost/PHPMyAdmin in your browser and click on New. Alt Text
  4. Create a database name(let name the database as db_name). Alt Text
  5. Create Connection
<?php $conn = mysqli_connect("localhost","root","","db_name");
?>
Enter fullscreen mode Exit fullscreen mode
                 OR
Enter fullscreen mode Exit fullscreen mode
<?php
$localhost='localhost';
$root='root';
$pass='';
$db_name='db_name';
mysqli_connect($localhost,$root,$pass,$db_name);
?>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)