How to connect the Database with PHP DOM page ?
To connect the database with PHP DOM page, do the following steps:
1. Create Database: Create a database using XAMPP, the name of database is “loginpage”. You can give any name to your database.
2. Create Table: Create table, inside “loginpage” database.
3. Create Table structure: Table should contain fields, according to your needs.
- id – primary key – auto increment
- name – varchar(100)
- password – varchar(100)
The datatype for name and password is varchar. The size can be alter as per the requirement. However, 100 is sufficient, and the datatype for “id” is int and it is a primary key. A primary key, also called a primary keyword, is a key in a relational database that is unique for each record. It is a unique identifier, such as a driver license number, telephone number (including area code), or vehicle identification number (VIN).
The structure of table will look like this
4. Insert values in the table:
After insertion, the table will look like this:
PHP Code: Create “connection.php” file. This is the connection code in PHP, to connect the database with any of your PHP DOM page.
"mysql:host=$servername; dbname= loginpage"
"Connection failed: "
Include the “connection.php” file inside the PHP DOM page.
After this, the database is connected with the PHP DOM page.My Personal Notes arrow_drop_up