6/3/2023 0 Comments Xampp phpmyadminHere, the servername is localhost, username is root and password is empty.īy using my_sqli_connect() function, we will establish a connection. Specify servername, mysql username and password fields in the PHP code. The first three steps are same as we did while establishing connection with MySQL in the earlier step.ġ. Let me explain the steps to create a database using PHP. Where database_name is the name of the database. Query Syntax: CREATE DATABASE database_name The CREATE command in SQL can be used to create a database. We are going to include a SQL Query statement in our PHP code to create the database. We can also do the same withe a piece of PHP code as described in the following section. If you see the "Connection established successfully" message, you're connected with XAMPP. Open your web browser and point it to URL. Heads Up: If you're using LAMP/LEMP stacks, you may need to update the MySQL root password in the above code. If you're on Windows, the htdocs will be usually in C:\xampp\ folder. Heads Up: If you use Linux, the htdocs folder will be under /opt/lampp/ directory. ![]() PHP Code To Connect To MySQLĬreate a new PHP file named Connect_data.php under the /htdocs directory with the following contents in it. Now, let us write a sample PHP code based on the above steps. This function will display an error, if the connection is failed. We can check the connection using the mysqli_connect_error() function specified in an if condition. ![]() It will also take a database name which is optional here, because we are only creating the connection.Ĭode: $connection = mysqli_connect($server_name, $user_name, $password) First will be the servername, second is the username (i.e. Create a connection using the above details.īy using mysqli_connect() function, we will establish a connection. Here, my servername is localhost, MySQL username is root and its password is empty.Ģ. Specify MySQL servername, username and password parameters in your PHP code. So, we will will be using XAMPP stack throughout this guide. Setting up XAMPP is much easier than LAMP and LEMP stacks.
0 Comments
Leave a Reply. |