Beispiel #1
0
 /**
  * Updates data in a table.
  *
  * @param   $table      JaxpMySqlTable
  *          Affected table.
  *          
  * @param   $row        JaxpMySqlRow
  *          Modified records.
  *          
  * @param   $conditions JaxpMySqlConditions
  *          Matches for original records. If null, it'll overwrite all data.
  *          
  * @return  int
  *          Number of affected rows.
  *          
  * @uses    JaxpMySqlTable, JaxpMySqlRow, JaxpMySqlConditions
  * @access  public
  * @since   1.1
  *
  * @internal    2010.01.03 -- fixed error with partial row updates.
  */
 function Update(JaxpMySqlTable $table, JaxpMySqlRow $row, JaxpMySqlConditions $conditions = null)
 {
     $sql_query_template = "UPDATE %s SET %s" . ($conditions ? " WHERE %s" : "");
     $destination_table = $table->TableName;
     # Get all fields from table, except auto-incremental ones.
     $fields = $row->GetColumnNames(true);
     # Match values with fields.
     foreach ($fields as $i => $f) {
         if ($row->Columns[$f]->Value) {
             $v = $row->Columns[$f]->HasQuotes() ? "'" . $row->Columns[$f]->Value . "'" : $row->Columns[$f]->Value;
             $update_sentences[] = "{$f} = {$v}";
         }
     }
     $update_list = implode(", ", $update_sentences);
     # If update conditions were specified, place them in the query.
     # Otherwise, build query without conditions.
     $sql_query = $conditions ? sprintf($sql_query_template, $destination_table, $update_list, $conditions->ParseToStringList()) : sprintf($sql_query_template, $destination_table, $update_list);
     # Execute query.
     mysql_query('SET NAMES utf8');
     mysql_query($sql_query);
     #echo $sql_query;
     # Return number of affected rows.
     return mysql_affected_rows();
 }
Beispiel #2
0
 /**
  * Locates a note using permalink data.
  *
  * @uses    JaxpDate
  * @uses    JaxpMySqlHandler
  * @uses    JaxpMySqlConditions
  *
  * @access  public
  * @return  JaxpJournalNote     An object representing the note.
  * @since   1.2.1
  */
 function GetNoteFromPermalink()
 {
     # Parse the URL address and take the last two parts
     # (i.e. from "/uri/a/b/c/", take 'b' and 'c', unslashed.
     list($date, $title) = array_slice(explode("/", $_SERVER["REQUEST_URI"]), 2, 2);
     # Convert date string to an usable object.
     $datePosted = new JaxpDate(JAXP_DATE_FROM_STRING, $date);
     # Reformat the title passed by GET.
     # Punctuation characters mutate to wildcards for LIKE-comparison.
     $title = str_replace("-", " ", $title);
     $title = str_replace("_", "%", $title);
     # Instantiate the Notes table.
     $journal_notes = $this->MySqlHandler->Database->Tables["journal_notes"];
     # Create a dual-condition filter, to locate by title and by date.
     $filter = new JaxpMySqlConditions();
     $filter->AddCondition($journal_notes->Columns["title"], $title, JAXP_MYSQL_MATCH_CONTAINS);
     $filter->AddCondition($journal_notes->Columns["date_posted"], $datePosted->ToTimestamp(), JAXP_MYSQL_MATCH_GREATER_OR_EQUAL_THAN);
     # Apply the filter.
     $note = $this->MySqlHandler->Select("SELECT * FROM journal_notes WHERE " . $filter->ParseToStringList());
     # Since the filter ensures only one entry will be retrieved,
     # return the first element of the resulting array.
     return $this->Notes[$note->Rows[0]->Columns["id"]->Value];
 }