function testPrepared() { (new NativeReactor())->run(function ($reactor) { $db = new Connection("host=" . DB_HOST . ";user="******";pass="******";db=connectiontest", null, $reactor); $db->connect(); $db->query("CREATE TEMPORARY TABLE tmp SELECT 1 AS a, 2 AS b"); $db->query("INSERT INTO tmp VALUES (5, 6), (8, 9)"); $stmt = (yield $db->prepare("SELECT * FROM tmp WHERE a = ? OR b = :num")); $base = ["catalog" => "def", "schema" => "connectiontest", "table" => "tmp", "original_table" => "tmp", "charset" => 63, "columnlen" => 1, "type" => 3, "flags" => 1, "decimals" => 0]; $this->assertEquals((yield $stmt->getFields()), [$base + ["name" => "a", "original_name" => "a"], $base + ["name" => "b", "original_name" => "b"]]); $result = (yield $stmt->execute([5, "num" => 9])); $this->assertEquals((yield $result->rowCount()), 2); $result = (yield $db->prepare("SELECT * FROM tmp WHERE a = ? OR b = ?", [5, 8])); $this->assertEquals((yield $result->rowCount()), 1); $stmt = (yield $db->prepare("INSERT INTO tmp VALUES (:foo, :bar)")); $stmt->bind("foo", 5); $result = (yield $stmt->execute(["bar" => 9])); $this->assertEquals($result->affectedRows, 1); }); }
function testPreparedWithNegativeValue() { \Amp\reactor(\Amp\driver()); \Amp\run(function () { $db = new Connection("host=" . DB_HOST . ";user="******";pass="******";db=connectiontest"); $db->connect(); $db->query("DROP TABLE tmp"); // just in case it would exist... (yield $db->prepare("CREATE TABLE tmp SELECT ? AS a", [-1])); $result = (yield $db->prepare("SELECT a FROM tmp", [])); $this->assertEquals((yield $result->fetchRow()), [-1]); }); }