Connecting your project to SQL Database comes with these 3 requirements.
1. Create 2 Pages (Optional tho' but safe) with these names:
In the first
config.php
Type these codes
DATABASE_HOST
This Database_host is by default a "localhost" since it is a test work done locally, using *AMP (APACHE, MYSQL, & PHP).
DATABASE_USER
The database user is by default "root" but can be alternated, So Just be sure what, before configurations
DATABASE_NAME
This a Name You Created In Your Database, therefore names vary, but let's assume it's "test_name"
DATABASE_CODE
The Code by default is Null (i.e Empty). If you have a Password use it.
on your config.php type...
Taaadaaah, You're Connected. To Test Connection write:
i.e means if connected echo "Connected", else echo "failed".
1. Create 2 Pages (Optional tho' but safe) with these names:
- config.php
- connect.php
In the first
config.php
Type these codes
<?php
define("DATABASE_HOST","localhost");
define("DATABASE_USER","root");
define("DATABASE_NAME","test_name");
define("DATABASE_CODE","");
?>
DATABASE_HOST
This Database_host is by default a "localhost" since it is a test work done locally, using *AMP (APACHE, MYSQL, & PHP).
DATABASE_USER
The database user is by default "root" but can be alternated, So Just be sure what, before configurations
DATABASE_NAME
This a Name You Created In Your Database, therefore names vary, but let's assume it's "test_name"
DATABASE_CODE
The Code by default is Null (i.e Empty). If you have a Password use it.
on your config.php type...
<?php
include_once 'config.php';
$conn = mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_CODE);
mysqli_select_db($conn, DATABASE_NAME);
?>
Taaadaaah, You're Connected. To Test Connection write:
<?php
include_once 'config.php';
$conn = mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_CODE);
$connection_status = ($conn) ? "Connected" : "Failed" ;
echo
$connection_status;mysqli_select_db($conn, DATABASE_NAME);
?>
i.e means if connected echo "Connected", else echo "failed".
Comments
Post a Comment