The PHP SDK can load a SurrealQL script into the database it is connected to, and can export the database. Both methods are only available on a remote database targeted with the http protocol.
| Method | Description |
|---|---|
$db->import($content, $username, $password) | Imports data into the database |
$db->export($username, $password) | Exports data from the database |
->import()
Imports data into a table.
Method Syntax
$db->import($content, $username, $password);Arguments
Arguments | Type | Description |
|---|---|---|
content |
| The content to import. |
username |
| The username to authenticate with. |
password |
| The password to authenticate with. |
Example usage
Example
// connect and select the namespace + database that the import function will use to import the data
$db->connect('http://localhost:8080', [
'namespace' => 'example',
'database' => 'example',
]);
// grab file contents and import the data
$import = file_get_contents('data.surql');
$db->import($import, 'admin', 'password'); ->export()
Exports data from a table.
Method Syntax
$db->export($username, $password);Arguments
Arguments | Type | Description |
|---|---|---|
username |
| The username to authenticate with. |
password |
| The password to authenticate with. |
Example usage
Example
// Connect to the remote database. For the export to work, the
// database must exist and contain data.
$db->connect('http://localhost:8080', [
'namespace' => 'example',
'database' => 'example',
]);
// Export data
$response = $db->export('admin', 'password');
// Create a file and write the response to it
$fp = fopen('exported_data.json', 'w');
// Write the response to the file
fwrite($fp, $response);
// Close the file
fclose($fp);