安装:
https://pecl.php.net/package/mysql_xdevapi/8.0.28/windows
在这里插入图片描述
mysql_xdevapi 是 MySQL 官方提供的 新一代面向文档和关系型的 API,支持 NoSQL(文档/集合)和 SQL(表)。

<?php
$session = mysql_xdevapi\getSession("mysqlx://root:password@localhost:33060");
$schema = $session->getSchema("testdb");

// 表操作
$table = $schema->getTable("user");
$table->insert("name", "age")->values("Alice", 22)->execute();
$result = $table->select("id", "name", "age")->execute();
foreach ($result->fetchAll() as $row) {
    print_r($row);
}

// 集合操作
$collection = $schema->getCollection("my_collection");
$collection->add(['name' => 'Bob', 'age' => 30])->execute();
$docs = $collection->find('age > 20')->execute()->fetchAll();
print_r($docs);
?>

更多推荐