有没有办法在同一个MongoDB或MySQL项目中使用? [关闭]

I'm a young developer and I've finished yesterday the structure of my new cms created for practice and my question is: Is possible to use MongoDB and MySQL for the same project?

Example: In the config I want to enable MySQL with pdo and disable MongoDB or enable MongoDB and disable MySQL.

For MySQL: $db->query("SELECT * FROM users");

For MongoDB: $db->users->find()

It's possible or there is a function to use the same syntax for get data from MySQL or MongoDB?

It's probably worth taking a look at Doctrine. It offers both an ORM (Object Relational Mapper) to handle your SQL database (MySQL, MariaDB, PostgreSQL) and an ODM (Object Document Mapper) to handle your NoSQL database (i.e. MongoDB).

These are good places to start from:

  1. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html
  2. http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/tutorials/getting-started.html

Sure, just use multiple instances.

// Init $mySQLDB whith mysql driver etc.
// Use $mySQLDB
$mySQLDB->query("SELECT * FROM users");

// Init $mongoDB with mongo driver etc.
// Use $mongoDB
$mongoDB->users->find();