What is the concept of ORM in PHP and how does it relate to database operations?

ORM (Object-Relational Mapping) in PHP is a programming technique that allows developers to work with databases using objects instead of raw SQL queries. ORM simplifies database operations by mapping database tables to PHP classes and objects, making it easier to perform CRUD (Create, Read, Update, Delete) operations without writing complex SQL queries.

// Example of using ORM in PHP with a library like Eloquent
// First, define a model class that represents a database table
class User extends Illuminate\Database\Eloquent\Model {
    protected $table = 'users';
}

// Then, use the model to perform database operations
// Create a new user
$user = new User();
$user->name = 'John Doe';
$user->email = 'john@example.com';
$user->save();

// Retrieve a user by ID
$user = User::find(1);

// Update a user
$user->name = 'Jane Doe';
$user->save();

// Delete a user
$user->delete();