-1

I have created a website for my versity project...But I am asked to add a database in it..That's why I need to know how to add a database via xamp in a website.

IHsojib
  • 11
  • 1
  • The question is either unclear or too broad. There are plenty tutorials out there teaching how to connect PHP to a database. – FirstOne Nov 25 '17 at 16:17
  • 1
    Possible duplicate of [How to use PHP to connect to sql server](https://stackoverflow.com/questions/18632607/how-to-use-php-to-connect-to-sql-server) – Shankar Nov 25 '17 at 16:23
  • @IronyStack XAMP is not SQL Server. Please, hover over the tag. – FirstOne Nov 25 '17 at 17:13

1 Answers1

0

Use this code to create a connection to your database from php

<?php
$servername = "localhost";
$username = "root";
$password ="db-password";
$dbname = "db-name";

//create connection
$conn = new mysqli($servername,$username,$password,$dbname);
//check connection
if ($conn->connect_error) {
    die("connection failed" .$conn->$connect_error);
}

?>

use this link to understand how to create and execute queries.

https://www.w3schools.com/php/php_mysql_connect.asp

Gaius Mathew
  • 187
  • 1
  • 8