BCA / B.Tech 12 min read

How to Configure Our Framework

How to Configure Our Framework in Hindi | How to Configure a Framework (Using MySQL in PHP): 


How to Configure our framework in Hindi | How to configure a framework in Hindi


  • To use MySQL in PHP, several frameworks are available, such as Laravel, CodeIgniter, Symfony, and others.
  • These frameworks are used to make projects faster and more organized.
  • Each framework has a configuration process to connect to a database (MySQL).
  • Using a PHP framework (like Laravel, CodeIgniter, Symfony) provides easy and secure integration with MySQL.
  • Laravel is great for large and structured projects.
  • CodeIgniter is good for fast and lightweight applications.
  • Symfony is perfect for advanced and large projects.
  • Configuring and structuring the database correctly in a framework streamlines the development process.

Below are the easy ways to configure MySQL using a framework in PHP explained.

Using MySQL in Laravel Framework in PHP in Hindi | Using MySQL in the Laravel Framework:

Laravel is a popular and powerful framework. Its use with MySQL is done in the following steps:

1. Install Laravel

composer create-project --prefer-dist laravel/laravel my_project

2. MySQL Configuration in the .env file

In Laravel, the .env file is used to configure database settings.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password

3. Create Database Migration and Model

To use MySQL in Laravel, migrations and models are created.

php artisan make:model User -m
This command will create a model named User.php and a migration file.

4. Update the migration file

Add the table structure to the file created in database/migrations:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamps();
    });
}

5. Run the migration

Run the migration to create the table in the database:

php artisan migrate

6. Adding and fetching data

You can add and fetch data in the MySQL database using Laravel's model.

Adding data:

User::create(['name' => 'Rahul', 'email' => '[email protected]']);
Reading data:

$users = User::all();
foreach ($users as $user) {
    echo $user->name;
}

Using MySQL in CodeIgniter Framework in PHP in Hindi | Using MySQL in the CodeIgniter Framework:

CodeIgniter is a lightweight and fast framework. To configure MySQL in it, follow the steps given below:

1. Download and install CodeIgniter

Download CodeIgniter and set it up on your server.

2. Configure the database 

Open the application/config/database.php file and add the MySQL details:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'your_username',
    'password' => 'your_password',
    'database' => 'your_database_name',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
);

3. Loading the database

Load the database in the Controller:

$this->load->database();

4. Adding and reading data

Adding data:

$data = array(
    'name' => 'Rahul',
    'email' => '[email protected]',
);
$this->db->insert('users', $data);
Reading data:

$query = $this->db->get('users');
foreach ($query->result() as $row) {
    echo $row->name;
}

Using MySQL in Symfony Framework in PHP in Hindi | Using MySQL in the Symfony Framework:

Symfony is an advanced framework. To connect it to MySQL:

1. Install Symfony

composer create-project symfony/website-skeleton my_project

2. Add MySQL details to the .env file

DATABASE_URL="mysql://your_username:[email protected]:3306/your_database_name"

3. Create entity and migration

php bin/console make:entity
php bin/console doctrine:migrations:migrate

4. Add and read data

Use Symfony's Doctrine ORM:
Adding data:

$user = new User();
$user->setName('Rahul');
$user->setEmail('[email protected]');
$entityManager->persist($user);
$entityManager->flush();
Reading data:

$users = $userRepository->findAll();
foreach ($users as $user) {
    echo $user->getName();
}