Create MySQL Database at the Localhost
Create MySQL Database at the Localhost
Localhost
First, let me tell you what PHPMyAdmin is. It is a control panel from
where you can manage your database that you have created. Open
your browser and go to localhost/PHPMyAdmin or click “Admin” in
XAMPP UI.
When you first installed XAMPP, it only created the username for it to
be accessed, you now have to add a password to it by yourself. For
this, you have to go to User account where the user is same as the
one shown in this picture:
Create Database
Now return to the homepage of phpmyadmin. Click New button to
create a new database.
1. <?php
2.
3. function OpenCon()
4. {
5. $dbhost = "localhost";
6. $dbuser = "root";
7. $dbpass = "1234";
8. $db = "example";
9.
10.
11. $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn ->
error);
12.
13.
14. return $conn;
15. }
16.
17. function CloseCon($conn)
18. {
19. $conn -> close();
20. }
21.
22. ?>
1. <?php
2. include 'db_connection.php';
3.
4. $conn = OpenCon();
5.
6. echo "Connected Successfully";
7.
8. CloseCon($conn);
9.
10. ?>
Run it!
Now open your browser and goto localhost/practice/index.php and you
should see this screen:
Confirmation Message