|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +sidebar_label: export |
| 4 | +title: Export Method in PHP | PHP SDK | Integration | SurrealDB |
| 5 | +description: Export data from a local or remote database using the export method with the SurrealDB PHP SDK. |
| 6 | +--- |
| 7 | + |
| 8 | +import Label from "@components/shared/Label.astro"; |
| 9 | + |
| 10 | +# `->export()` {#export} |
| 11 | + |
| 12 | +Exports data from a table. |
| 13 | + |
| 14 | +> [!NOTE] |
| 15 | +> This method is only available on a remote database targeted with the http protocol. |
| 16 | +
|
| 17 | + |
| 18 | +```php title="Method Syntax" |
| 19 | +$db->export($username, $password); |
| 20 | +``` |
| 21 | + |
| 22 | +### Arguments |
| 23 | + |
| 24 | +<table> |
| 25 | + <thead> |
| 26 | + <tr> |
| 27 | + <th colspan="2" scope="col">Arguments</th> |
| 28 | + <th colspan="2" scope="col">Type</th> |
| 29 | + <th colspan="2" scope="col">Description</th> |
| 30 | + </tr> |
| 31 | + </thead> |
| 32 | + <tbody> |
| 33 | + <tr> |
| 34 | + <td colspan="2" scope="row" data-label="Arguments"> |
| 35 | + <code>username</code> |
| 36 | + <Label label="required" /> |
| 37 | + </td> |
| 38 | + <td colspan="2" scope="row" data-label="Type"> |
| 39 | + `string` |
| 40 | + </td> |
| 41 | + <td colspan="2" scope="row" data-label="Description"> |
| 42 | + The username to authenticate with. |
| 43 | + </td> |
| 44 | + </tr> |
| 45 | + <tr> |
| 46 | + <td colspan="2" scope="row" data-label="Arguments"> |
| 47 | + <code>password</code> |
| 48 | + <Label label="required" /> |
| 49 | + </td> |
| 50 | + <td colspan="2" scope="row" data-label="Type"> |
| 51 | + `string` |
| 52 | + </td> |
| 53 | + <td colspan="2" scope="row" data-label="Description"> |
| 54 | + The password to authenticate with. |
| 55 | + </td> |
| 56 | + </tr> |
| 57 | + </tbody> |
| 58 | +</table> |
| 59 | + |
| 60 | +### Example |
| 61 | + |
| 62 | +```php title="Example" |
| 63 | + |
| 64 | +// connect to the remote database. For the export to work, the database must exists with also existing data. |
| 65 | +$db->connect('http://localhost:8080', [ |
| 66 | + 'namespace' => 'example', |
| 67 | + 'database' => 'example', |
| 68 | +]); |
| 69 | + |
| 70 | +// Export data |
| 71 | +$response = $db->export('admin', 'password'); |
| 72 | + |
| 73 | +// Create a file and write the response to it |
| 74 | +$fp = fopen('exported_data.json', 'w'); |
| 75 | + |
| 76 | +// Write the response to the file |
| 77 | +fwrite($fp, $response); |
| 78 | + |
| 79 | +// Close the file |
| 80 | +fclose($fp); |
| 81 | +``` |
0 commit comments