A fast, secure, and easy modern SQL library for PHP
Seamlessly work with PostgreSQL, MySQL, SQLite, Sybase, Oracle, and MSSQL databases
- 🚀 Simple & Intuitive API - Write less, do more with a clean, fluent interface
- 🔒 Secure by Default - Built-in protection against SQL injection
- 🔄 Multi-Database Support - Works with PostgreSQL, MySQL, SQLite, Sybase, Oracle, and MSSQL
- 🧩 Modular Design - Use only what you need with a lightweight core
- 📊 Powerful Query Builder - Construct complex queries with ease
- 🛠️ Schema Management - Create and modify database structures programmatically
- 🏗️ Migration System - Laravel-inspired migrations for managing database schema changes
composer require foxql/foxql
// Create a new FoxQL instance with MySQL connection
try {
$db = new \FoxQL\FoxQL([
'type' => 'mysql', // Database type: mysql, pgsql, sqlite, etc.
'database' => 'my_database',
'host' => 'localhost',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8mb4', // Character set
'prefix' => 'prefix_' // Table prefix (optional)
]);
// Insert data
$db->insert('users', [
'name' => 'John Doe',
'email' => '[email protected]'
]);
// Select data
$users = $db->select('users', '*');
print_r($users);
} catch (\PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
FoxQL includes a powerful migration system for managing database schema changes:
// Create a table using the migration builder
$db->createTable('users', function($table) {
$table->increments('id');
$table->string('name', 100)->notNull();
$table->string('email', 100)->notNull()->unique();
$table->timestamps(); // Adds created_at and updated_at columns
});
// Run migrations from a directory
$migrations = $db->migrate('/path/to/migrations');
// See the complete example in examples/migration_example.php
Explore our comprehensive documentation for detailed usage instructions:
Basic Operations | Data Manipulation | Schema Management | Raw SQL |
---|---|---|---|
Connection | Insert | Create Table | Query |
Select | Update | Drop Table | Execute |
Get | Delete | Action | |
Has | Replace | Migration |
Statistical | Mathematical | Other |
---|---|---|
Count | Sum | Rand |
Average | Max | |
Min |
FoxQL is open-sourced software licensed under the MIT license.
- Name: Hossein Pira
- Telegram: @h3dev
- Email: [email protected]
- LinkedIn: https://www.linkedin.com/in/hossein-pira-748056278