Skip to content

Commit

Permalink
bit column bind support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcrypster committed Aug 11, 2023
1 parent 3f32c9d commit 9269218
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mysqly.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ public static function exec($sql, $bind = []) {
}

$statement = static::$db->prepare($sql);
$statement->execute($params);
if ( $params ) {
foreach ( $params as $k => $v ) {
$type = PDO::PARAM_STR;
if ( is_int($v) ) $type = PDO::PARAM_INT;
else if ( is_null($v) ) $type = PDO::PARAM_NULL;
else if ( is_bool($v) ) $type = PDO::PARAM_BOOL;
$statement->bindValue($k, $v, $type);
}
}
$statement->execute();

return $statement;
}
Expand Down
Binary file added tests/.tests.php.swp
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public static function test_now() {
'Checking current timestamp');
}

public static function test_bit() {
mysqly::query('TRUNCATE test_bit');
mysqly::insert('test_bit', ['flag' => true]);
self::assert(true, (bool)mysqly::one('SELECT flag FROM test_bit LIMIT 1'), 'Testing BIT column value / true');

mysqly::query('TRUNCATE test_bit');
mysqly::insert('test_bit', ['flag' => false]);
self::assert(false, (bool)mysqly::one('SELECT flag FROM test_bit LIMIT 1'), 'Testing BIT column value / false');
}

public static function test_fetch() {
$new_id1 = mysqly::insert('test', ['age' => 29, 'name' => 'Test Fetch 1']);
$new_id2 = mysqly::insert('test', ['age' => 29, 'name' => 'Test Fetch 2']);
Expand Down

0 comments on commit 9269218

Please sign in to comment.