From 73713e8d515c0c9912a880355f5cc27dc026f967 Mon Sep 17 00:00:00 2001 From: absurdo Date: Fri, 17 Nov 2023 01:52:08 +0100 Subject: [PATCH] Fixes in insert --- src/WPDO.php | 10 ++++++++-- tests/WPDOTest.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/WPDO.php b/src/WPDO.php index 16aa407..36b085f 100644 --- a/src/WPDO.php +++ b/src/WPDO.php @@ -165,7 +165,13 @@ class WPDO { } - public function insert($fields, $values) { + public function insert($values) { + + $fields=array_keys($values); + + $values=array_values($values); + + print_r($values); $fields=$this->check_fields($fields); @@ -178,7 +184,7 @@ class WPDO { $final_fields=implode('`, `', $fields); $query='insert into '.$this->table->name.' (`'.$final_fields.'`) VALUES ('.implode(',', array_fill(0, count($fields), '?')).')'; - //echo $query; + $this->sth=$this->conn->prepare($query); return $this->sth->execute($values); diff --git a/tests/WPDOTest.php b/tests/WPDOTest.php index c1c9b67..280fe62 100644 --- a/tests/WPDOTest.php +++ b/tests/WPDOTest.php @@ -50,7 +50,7 @@ final class WPDOTest extends TestCase { $this->assertEquals('table_test', $pdo->table->name); - $this->assertTrue($pdo->insert(['name', 'last_name', 'type'], ['first', 'last', '1'])); + $this->assertTrue($pdo->insert(['name' => 'first', 'last_name' => 'last', 'type' => 1])); }