/** * @return bool|Error */ public function execute() { $set_string = ""; foreach ($this->fields as $k => $v) { $set_string .= $k . "=:" . $k . ","; } $set_string = substr($set_string, 0, -1); $sql = 'UPDATE ' . $this->table . ' SET ' . $set_string . ' WHERE id=:id'; $db = $this->fmPdo->getConnection(); try { $query = $db->prepare($sql); } catch (Exception $e) { return new Error($e); } $query->bindParam(':id', $this->id, PDO::PARAM_STR); foreach ($this->fields as $k => $v) { $query->bindParam(':' . $k, $v[0], PDO::PARAM_STR); } try { if (!$query) { return new Error($this->fmpdo->errorInfo()); } $result = $query->execute(); } catch (Exception $e) { return new Error($e); } return $result; }
/** * Assembles the object properties and executes the SQL SELECT statement * @return Error|Result */ public function execute() { $db = $this->fmPdo->getConnection(); try { $query = $db->prepare($this->assemble()); if (!$query) { return new Error($db->errorInfo()); } foreach ($this->findCriteria as $k => $v) { $query->bindParam(':' . $k, $v['value'], PDO::PARAM_STR); } $result = $query->execute(); } catch (Exception $e) { return new Error($e); } $rows = $query->fetchAll(); if (count($rows) > 0) { return new Result($this->table, $rows); } else { return new Error("No records found", "401"); } }
public function testGetConnection() { $this->assertInstanceOf('\\PDO', $this->fmPdo->getConnection()); $this->assertInstanceOf('\\Rjakes\\FmPdo\\Connect', $this->fmPdo->getConnection()); }