use Schema\Connection\MySQLConnection; $conn = new MySQLConnection([ 'host' => 'localhost', 'username' => 'root', 'password' => 'password', 'database' => 'my_database' ]); $result = $conn->query('SELECT * FROM my_table'); while ($row = $result->fetch()) { echo $row['id'] . " - " . $row['name'] . "\n"; }
use Schema\Connection\MongoDBConnection; $conn = new MongoDBConnection([ 'host' => 'localhost', 'username' => 'admin', 'password' => 'password', 'database' => 'my_database' ]); $result = $conn->query('my_collection')->find(); foreach ($result as $doc) { echo $doc['name'] . " - " . $doc['age'] . "\n"; }In the above examples, we are using the PHP Schema Connection library to connect to a MySQL and MongoDB database. The library abstracts away the differences in the connection details, allowing us to use the same code to interact with different database systems. The PHP Schema Connection library is part of the wider Schema package, which includes other related libraries such as the Schema Builder and Schema Validator.