Update database.php
This commit is contained in:
parent
11ad3b0ee8
commit
b45e7ceac9
|
|
@ -444,12 +444,13 @@ include "root.php";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function add() {
|
public function add() {
|
||||||
//connect to the database if needed
|
//connect to the database if needed
|
||||||
if (!$this->db) {
|
if (!$this->db) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
}
|
}
|
||||||
|
//count the fields
|
||||||
|
$field_count = count($this->fields);
|
||||||
//add data to the database
|
//add data to the database
|
||||||
$sql = "insert into ".$this->table;
|
$sql = "insert into ".$this->table;
|
||||||
$sql .= " (";
|
$sql .= " (";
|
||||||
|
|
@ -457,44 +458,44 @@ include "root.php";
|
||||||
if (is_array($this->fields)) {
|
if (is_array($this->fields)) {
|
||||||
foreach($this->fields as $name => $value) {
|
foreach($this->fields as $name => $value) {
|
||||||
if (count($this->fields) == $i) {
|
if (count($this->fields) == $i) {
|
||||||
$sql .= $name." ";
|
$sql .= $name." \n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= $name.", ";
|
$sql .= $name.", \n";
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql .= ") ";
|
$sql .= ") \n";
|
||||||
$sql .= "values ";
|
$sql .= "values \n";
|
||||||
$sql .= "(";
|
$sql .= "(\n";
|
||||||
$i = 1;
|
$i = 1;
|
||||||
if (is_array($this->fields)) {
|
if (is_array($this->fields)) {
|
||||||
foreach($this->fields as $name => $value) {
|
foreach($this->fields as $name => $value) {
|
||||||
if (count($this->fields) == $i) {
|
if ($field_count == $i) {
|
||||||
if (strlen($value) > 0) {
|
if (strlen($value) > 0) {
|
||||||
//$sql .= "'".$value."' ";
|
//$sql .= "'".$value."' ";
|
||||||
$sql .= ":".$value." ";
|
$sql .= ":".$name." \n";
|
||||||
$params[$name] = $value;
|
$params[$name] = $value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= "null ";
|
$sql .= "null \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (strlen($value) > 0) {
|
if (strlen($value) > 0) {
|
||||||
//$sql .= "'".$value."', ";
|
//$sql .= "'".$value."', ";
|
||||||
$sql .= ":".$value.", ";
|
$sql .= ":".$name.", \n";
|
||||||
$params[$name] = $value;
|
$params[$name] = $value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= "null, ";
|
$sql .= "null, \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql .= ")";
|
$sql .= ")\n";
|
||||||
|
|
||||||
//execute the query, show exceptions
|
//execute the query, show exceptions
|
||||||
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue