Middle
What databases have you used in your stack?
sobes.tech AI
Answer from AI
In my PHP stack, I used several databases depending on the task:
- MySQL / MariaDB — the main relational database for storing structured data, supporting transactions, complex queries, and indexes.
- PostgreSQL — used for projects requiring extended support for data types, full-text search, and more complex queries.
- Redis — as an in-memory store for caching, sessions, and message queues.
- MongoDB — used for storing documents and data with a dynamic schema, especially when the data structure changes frequently.
Example of connecting to MySQL using PDO:
$pdo = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'user', 'password');
$stmt = $pdo->query('SELECT * FROM users');
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
The choice of database depends on data requirements, speed, and scalability.