public static function prepared($query, $bindvals) { $stmt = self::$mysqli->prepare($query); if ($stmt) { $bindParam = new BindParam(); if (is_array($bindvals)) { foreach ($bindvals as &$val) { $bindParam->add($val); } } else { $bindParam->add($bindvals); } if (count($bindvals) > 0) { call_user_func_array(array($stmt, 'bind_param'), makeValuesReferenced($bindParam->get())); } if ($stmt->execute()) { if ($stmt->affected_rows === -1) { $result = $stmt->get_result(); return new ResultSet(self::$mysqli, $result, $query); } else { return true; } } } else { self::log("Failed to prepare query." . self::error(), YG_WARNING); return false; } }
public function update($where, $info) { $insert_string = ""; $isfirst = true; $types = ""; foreach ($info as $field => $value) { if (!array_key_exists(strtolower($field), $this->fields)) { die("wrong row used in '.insert()'; row {$name} does not exist in table {$this->name}."); } if (gettype($value) == "array") { die("not supported yet: " . xdebug($value)); } if ($isfirst) { $isfirst = false; $insert_string .= "`{$field}` = ?"; } else { $insert_string .= ", `{$field}` = ?"; } $type = gettype($value); $types .= substr($type, 0, 1); $params[] =& $info[$field]; } $where = $this->database->createWhereClausule($where, $this); $bind_param_args = $where['bind_param']; $whereclausule = $where['where_clausule']; $bind_param_args = array_merge(array($types . $bind_param_args[0]), $params, array_slice($bind_param_args, 1)); $sql_query = "UPDATE `{$this->name}` SET {$insert_string}{$whereclausule}"; $func_args = array_merge(array($types), $params); if (!($mysqli_exec = $this->connection->prepare($sql_query))) { die(mysqli_error($this->connection)); } call_user_func_array(array($mysqli_exec, 'bind_param'), makeValuesReferenced($bind_param_args)); $mysqli_exec->execute(); $id = $this->connection->insert_id; return $id; }
function execSQL() { //point,query,format,params $array = func_get_args(); $count = func_num_args(); if ($count < 1) { generateError("Insufficient arguments", "CRITIAL ERROR", "NO POINT GIVEN", $array); } if ($count < 2) { generateError("Insufficient arguments", "Insufficient Arguments", $array[0], $array); } $myDB = dbConnect(); $query = $myDB->prepare($array[1]); if (!$query) { generateError("Query went false", "Query failure", "execSQL 1+" . $array[0], $array); } if ($count > 2) { $passArr = array(); array_push($passArr, $array[2]); for ($i = 3; $i < $count; $i++) { array_push($passArr, $array[$i]); } call_user_func_array(array($query, "bind_param"), makeValuesReferenced($passArr)); if (!$query) { generateError("Query went false", "Query failure", "execSQL 2+" . $array[0], $array); } } $query->execute(); if (!$query || $query->error) { if ($query) { $msg = "Query errored: " . $query->errorInfo(); } else { $msg = "Query went false"; } generateError($msg, "Query failure", "execSQL 3+" . $array[0], $array); return false; } if (strtolower(substr($array[1], 0, 6)) == 'insert') { return $query->insert_id; } else { //not an Insert, so just return true; return true; } }