1. Go to this page and download the library: Download jonbaldie/type-db library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jonbaldie / type-db example snippets
declare(strict_types=1);
$connection = new \TypeDb\Connection(new \PDO('sqlite::memory:'));
$connection->quickQuery(
'create table if not exists type_db_ft ( id int not null, value varchar not null )',
);
$connection->quickQuery(
'insert into type_db_ft (id, value) values (?, ?), (?, ?)',
[\TypeDb\to_sql(1), \TypeDb\to_sql('bar'), \TypeDb\to_sql(2), \TypeDb\to_sql('baz')]
);
$result = $connection->quickQuery(
'select id, value from type_db_ft where id = ? or value = ?',
[\TypeDb\to_sql(1), \TypeDb\to_sql('baz')]
);
declare(strict_types=1);
// 1. Return an object of type \TypeDb\SqlValue\SqlString
$string = \TypeDb\to_sql("foo bar");
// Grab the actual string we just passed in:
$value = $string->value;
// 2. Return an object of type \TypeDb\SqlValue\SqlFloat
$float = \TypeDb\to_sql(1.0);
// To get the actual float back:
$value = $float->value;
// 3. Return an object of type \TypeDb\SqlValue\SqlInteger
$integer = \TypeDb\to_sql(1);
// To get the actual integer back:
$value = $integer->value;
// 4. Return an object of type \TypeDb\SqlValue\SqlNull
$null = \TypeDb\to_sql(null);
// \TypeDb\SqlValue\SqlNull is the only one without a $value property!
declare(strict_types=1);
$string = new \TypeDb\SqlValue\SqlString("foo bar");
$float = new \TypeDb\SqlValue\SqlFloat(1.0);
$integer = new \TypeDb\SqlValue\SqlInteger(1);
$null = new \TypeDb\SqlValue\SqlNull();
declare(strict_types=1);
// This will return "foo bar"
$string = \TypeDb\from_sql(new \TypeDb\SqlValue\SqlString("foo bar"));
// This will return 1.0
$float = \TypeDb\from_sql(new \TypeDb\SqlValue\SqlFloat(1.0));
// This will return 1
$integer = \TypeDb\from_sql(new \TypeDb\SqlValue\SqlInteger(1));
// This will return null
$null = \TypeDb\from_sql(new \TypeDb\SqlValue\SqlNull);
declare(strict_types=1);
$connection = new \TypeDb\Connection(new \PDO('sqlite::memory:'));
$result = \TypeDb\quick_query(
$connection,
"select id, value from type_db_ft where id = ? or value = ?",
[\TypeDb\to_sql(1), \TypeDb\to_sql('baz')]
);
/*
$result looks like [
[
'id' => new \TypeDb\SqlValue\SqlInteger(1),
'value' => new \TypeDb\SqlValue\SqlString('bar'),
],
[
'id' => new \TypeDb\SqlValue\SqlInteger(2),
'value' => new \TypeDb\SqlValue\SqlString('baz'),
],
];
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.