What are some recommended libraries or tools for managing database queries in PHP, such as Doctrine or Eloquent?

When working with databases in PHP, it is recommended to use libraries or tools that help manage database queries efficiently. Doctrine and Eloquent are popular ORM (Object-Relational Mapping) libraries that provide an abstraction layer for database operations, making it easier to interact with databases in a more object-oriented manner.

// Example using Eloquent ORM
// First, install Eloquent via Composer: composer require illuminate/database

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'database_name',
    'username'  => 'root',
    'password'  => 'password',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
]);

$capsule->setAsGlobal();
$capsule->bootEloquent();

// Now you can use Eloquent models to interact with the database