|
28 | 28 | ## Example |
29 | 29 |
|
30 | 30 | ```bash |
31 | | -$ composer install sqlitecloud/sqlitecloud |
| 31 | +$ composer require sqlitecloud/sqlitecloud |
32 | 32 | ``` |
33 | 33 |
|
34 | 34 | ```php |
35 | 35 | <?php |
36 | 36 |
|
| 37 | +require_once 'vendor/autoload.php'; |
| 38 | + |
37 | 39 | use SQLiteCloud\SQLiteCloudClient; |
38 | 40 | use SQLiteCloud\SQLiteCloudRowset; |
39 | 41 |
|
40 | | -# Open the connection to SQLite Cloud |
| 42 | +// Open the connection to SQLite Cloud |
41 | 43 | $sqlite = new SQLiteCloudClient(); |
42 | 44 | $sqlite->connectWithString('sqlitecloud://myhost.sqlite.cloud:8860?apikey=myapikey'); |
43 | 45 |
|
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"); |
48 | 50 | $db_name = 'chinook.sqlite'; |
49 | 51 | $sqlite->execute("USE DATABASE {$db_name}"); |
50 | 52 |
|
51 | 53 | /** @var SQLiteCloudRowset */ |
52 | | -$rowset = $sqlite->execute('SELECT * FROM albums WHERE AlbumId = 1'); |
| 54 | +$rowset = $sqlite->execute('SELECT * FROM albums WHERE ArtistId = 2'); |
53 | 55 |
|
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 | +} |
57 | 61 |
|
58 | | -$sqlite->disconnect() |
| 62 | +$sqlite->disconnect(); |
59 | 63 | ``` |
0 commit comments