Fixes in insert
This commit is contained in:
parent
2d029548f2
commit
73713e8d51
2 changed files with 9 additions and 3 deletions
10
src/WPDO.php
10
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);
|
$fields=$this->check_fields($fields);
|
||||||
|
|
||||||
|
|
@ -178,7 +184,7 @@ class WPDO {
|
||||||
$final_fields=implode('`, `', $fields);
|
$final_fields=implode('`, `', $fields);
|
||||||
|
|
||||||
$query='insert into '.$this->table->name.' (`'.$final_fields.'`) VALUES ('.implode(',', array_fill(0, count($fields), '?')).')';
|
$query='insert into '.$this->table->name.' (`'.$final_fields.'`) VALUES ('.implode(',', array_fill(0, count($fields), '?')).')';
|
||||||
//echo $query;
|
|
||||||
$this->sth=$this->conn->prepare($query);
|
$this->sth=$this->conn->prepare($query);
|
||||||
|
|
||||||
return $this->sth->execute($values);
|
return $this->sth->execute($values);
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ final class WPDOTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals('table_test', $pdo->table->name);
|
$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]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue