Showing posts with label phpMyAdmin. Show all posts
Showing posts with label phpMyAdmin. Show all posts

Saturday, July 18, 2020

How to setup Database for CakePHP 4 Application?

Hi guys, In the last article we have seen the strategy for CakePHP application development, till now in the series of articles we have seen the different aspects of CakePHP application development, Its installation, basic configuration, setting up database server, MVC design pattern, the strength of ORM and RDF (Rapid Development Framework) Bake console Utility, which is a plug-in of CakePHP. 

If you have not seen previous articles visit the home page of Deep Space

As discussed in the last article the best approach of starting the application in CakePHP is Database First. So we need database, before we start developing application. For the purpose of learning, I have downloaded a classic database from MySQL Tutorial. You can download the sample database form this website. The downloaded file will be in a zip file format. 

Now open the phpMyAdmin application in your web browser using (localhost/phpmyadmin) address. Once the phpMyAdmin interface opened, click on the import button and chose your downloaded database zip file. This zip file contains the MySQL script. After executing the script you can verify by clicking on the database name in the left pan. 

Important: If you want to change the name of your database, open the script file and change the database name in script file. In my case I have changed it to “myshop”. 



After clicking on the table name under the database, you can see the table has seeded data as well for application development. 

The last step is to create a database user, who will connect the database from the application and grant the privileges to user for secure database access. If you have no idea about this check my article How to Interact with MySQL?

OK, we have setup our sample database for application development today, in the next article we will move to application side and see how to connect to this database and more. Stay tuned with us and like, share, follow and subscribe whatever option you have to be updated with our new articles.


Tuesday, July 14, 2020

How to Interact with MySQL?



Welcome, in our last article we have seen that CakePHP 4.0 application is up and running, but it was not able to connect to the database. The reason behind this is that we have not yet created any database. To make connection with database it is good idea to learn some basics about MySQL before proceeding further in CakePHP 4.0 application development. 

phpMyAdmin

phpMyAdmin is PHP based MySQL administration tool, it is free and by default installed with XAMPP control panel. There are many free and paid tools for MySQL administration but for the learning and development purpose phpMyAdmin is more than enough. 

Let’s start phpMyAdmin, go to your windows start menu and start the XAMPP control panel. Start the Apache service and MySQL service. When both services are up and running, jump to web browser and type “localhost/phpMyAdmin”. It will start the application and you will see the page like below.

phpMyAdmin

Create New User in MYSQL

Click on the “User Accounts” menu on the menu bar as shown in the image.

phpMyAdmin

Click on “Add User Account”. 

phpMyAdmin


On the Login information form enter the login information in “User Name” and in “Password” text boxes, type the same password again in the “Re-Type” text box.

phpMyAdmin

Click on the “Go” button given on the extreme right bottom of the page. If not visible scroll down the page.

At this stage a new database user is created. Till now we have not assigned any privileges to this user. We will do this later in the article.

Create New Database

Click on the “Databases” menu.
Enter the database name in the text box, as I entered “MySchool”, you can enter name of your database.

phpMyAdmin

Next click on the “Create” button. It will create the new database and will lead you to new page for New Table creation.

Create a New Table in Database

1) Enter the table name “Students” in the name field. You can enter your table name. in the number of column text box enter the count of your table columns in my case I have entered 3.

phpMyAdmin

Click on the “Go” button, on right side of the page.

On the next page fill the data as shown in the below image.

phpMyAdmin


Click on the “Save” button in the right bottom of form. it will create the new table.

Assign Privileges to User

Go to “User Accounts” page.

Select the Used “DBAdmin” by checking the checkbox in my case.

phpMyAdmin

Click on the “Edit Privileges” link. 

Click on “Databases” tab. Select the “MySchool” database and click on “Go” button 

phpMyAdmin


Now the database is selected for privileges. Click on “Go” button.

At this stage we have created a new user, created a new database, created a new table and assigned the privileges to the newly created user for the newly created database.

Stay tuned with us, in the next article we will move back to CakePHP and connect our application to this database.