PreparedQueryTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication;
  5. use YdbPlatform\Ydb\Ydb;
  6. class PreparedQueryTest extends TestCase
  7. {
  8. public function testPreparedQuery(){
  9. $config = [
  10. // Database path
  11. 'database' => '/local',
  12. // Database endpoint
  13. 'endpoint' => 'localhost:2136',
  14. // Auto discovery (dedicated server only)
  15. 'discovery' => false,
  16. // IAM config
  17. 'iam_config' => [
  18. 'insecure' => true,
  19. ],
  20. 'credentials' => new AnonymousAuthentication()
  21. ];
  22. $ydb = new Ydb($config);
  23. $table = $ydb->table();
  24. $session = $table->createSession();
  25. $prepared_query = $session->prepare('
  26. declare $pk as Int64;
  27. select $pk;');
  28. $x = 2;
  29. $result = $session->transaction(function($session) use ($prepared_query, $x){
  30. return $prepared_query->execute([
  31. 'pk' => $x,
  32. ]);
  33. });
  34. self::assertEquals($x,
  35. $result->rows()[0]['column0']
  36. );
  37. }
  38. }