Skip to content

Commit 1a5df26

Browse files
committed
chore(readme): example
1 parent b716ee2 commit 1a5df26

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,36 @@
2828
## Example
2929

3030
```bash
31-
$ composer install sqlitecloud/sqlitecloud
31+
$ composer require sqlitecloud/sqlitecloud
3232
```
3333

3434
```php
3535
<?php
3636

37+
require_once 'vendor/autoload.php';
38+
3739
use SQLiteCloud\SQLiteCloudClient;
3840
use SQLiteCloud\SQLiteCloudRowset;
3941

40-
# Open the connection to SQLite Cloud
42+
// Open the connection to SQLite Cloud
4143
$sqlite = new SQLiteCloudClient();
4244
$sqlite->connectWithString('sqlitecloud://myhost.sqlite.cloud:8860?apikey=myapikey');
4345

44-
# You can autoselect the database during the connect call
45-
# by adding the database name as path of the SQLite Cloud
46-
# connection string, eg:
47-
# $sqlite->connectWithString("sqlitecloud://myhost.sqlite.cloud:8860/mydatabase?apikey=myapikey");
46+
// You can autoselect the database during the connect call
47+
// by adding the database name as path of the SQLite Cloud
48+
// connection string, eg:
49+
// $sqlite->connectWithString("sqlitecloud://myhost.sqlite.cloud:8860/mydatabase?apikey=myapikey");
4850
$db_name = 'chinook.sqlite';
4951
$sqlite->execute("USE DATABASE {$db_name}");
5052

5153
/** @var SQLiteCloudRowset */
52-
$rowset = $sqlite->execute('SELECT * FROM albums WHERE AlbumId = 1');
54+
$rowset = $sqlite->execute('SELECT * FROM albums WHERE ArtistId = 2');
5355

54-
print('First colum, first row: ' . $rowset->value(0, 0));
55-
print('Second colum, first row: ' . $rowset->value(0, 1));
56-
print('column name: ' . $rowset->name(1));
56+
printf('%d rows' . PHP_EOL, $rowset->nrows);
57+
printf('%s | %s | %s' . PHP_EOL, $rowset->name(0), $rowset->name(1), $rowset->name(2));
58+
for ($i = 0; $i < $rowset->nrows; $i++) {
59+
printf('%s | %s | %s' . PHP_EOL, $rowset->value($i, 0), $rowset->value($i, 1), $rowset->value($i, 2));
60+
}
5761

58-
$sqlite->disconnect()
62+
$sqlite->disconnect();
5963
```

0 commit comments

Comments
 (0)