Technik, Gothic und Anderes

Technik ist Spiel, Gothic ist ernst und Zeit hat man zuviel

Archiv

Installation von Drupal ohne “CREATE TEMPORARY TABLE” Rechte unter MySQL

Geschrieben von skaldrom am 27. September 2007

Problem

Drupal

Some hosting providers do not grant the MySQL-userright CREATE TEMPORARY TABLES to their customers. Maybe because it’s full moon at the moment and everyone seems a bit crazy. But a href=”http://drupal.org/”>Drupal really wants this right and so a workaround is needed :-(

The error during the installation could be something like this:

user warning: Access denied for user: 'drupal@%' to database 'drupal' query: CREATE
TEMPORARY TABLE missing_nids SELECT n.nid, n.created, n.uid FROM node n LEFT
JOIN node_comment_statistics c ON n.nid = c.nid WHERE c.comment_count IS NULL in
/var/websites/drupal/includes/database.mysql.inc on line 167.

Kind of a Solution

I have written a patch for Drupal 5.2 which should kinda solve the problem. In Drupal, CREATE TEMPORARY TABLES is only used in the db_query_temporary function, found in the file includes/database.mysql.inc, which is a very clean progamming style! Basically, this patch creates a real table instead of a temporary one. The name and the creationdate is stored in an extra table called temporary_table. The cron.php removes these tables on a regular base. If the table already exists, it is dropped.

This patch only works for MySQL and MySQLI and may be a performance loss. I have tested this patch only on a low traffic site and I do not know if there are race conditions. Use it on your own risk…

Addendum

Another solution has been posted at Drupal.org.

Here it is: Patch to use Drupal without the CREATE TEMPORARY TABLES.

To apply it, change into the Drupal base directory and issue patch -p0<drupalwotemptables.patch on the commandline.

Ähnliche Artikel

Eingeordnet in Web | Keine Kommentare »

Unicode-Hölle: PHP, Apache, Mysql und Symfony in UTF-8

Geschrieben von skaldrom am 20. November 2006

Ich will mein altes ASCII wieder!!! Unicode ist die Hölle. Vielleicht helfen folgende Dinge dem, der damit rumkämpfen will/muss:

  • Im ganzen Pfad muss die Codierung stimmen bzw. gezielt umgewandelt werden. In unserem Beispiel also Dateisystem, Datenbank, (PHP), Applikation und Browser.
  • Glaube nicht was Du siehst! Was angezeigt wird ist wieder aus einer Applikation die irgendwie encodiert.
  • Firefox: View -> Character Encoding ist Dein Freund. Damit sieht man, was der Browser denkt er erhalte und das Umschalten auf 8859-1 kann zeigen, dass man es noch nicht geschafft hat und immernoch das alte Encoding verwendet wird.
  • utf8_encode() und utf8_decode() sind böse! Wenn man die braucht stimmt etwas nicht.

Hier ein paar Hilfen und Tools.

Dateisystem:

locale -a zeigt die Codierungen. Auf Debian kann man mittels dpkg-reconfigure locales einiges umstellen. Hier mal Unicode zu haben schadet nicht.

Konvertierung mit recode:

Folgendes Kommando wandelt eine Datei in ISO88591 in Unicode um:

recode ISO-8859-1..UTF-8 DATEI

Mysql:
Um Daten in UTF-8 abzulegen, muss:

  • das charset stimmen
  • die Verbindung vom Client zum Server stimmen
  • die Datenbank eine Collation “utf8_unicode_ci” besitzen
  • jede Tabelle eine Collation “utf8_unicode_ci” besitzen
  • die Daten in UTF-8 abgefüllt sein

Für das Abfüllen eignet sich mysql-query-browser, da dieser schon mit utf-8 arbeiten kann, was bei der Konsole nicht immer ganz sicher ist.

  • Tools: SHOW VARIABLES LIKE ‘character%’,damit sieht man, wie man unterwegs ist
  • set names utf8 zwingt die Verbindung zu utf8
  • select _utf8′Trällöällä’ wandelt den String inUTF-8

Apache:

Irgendwo im Conf sollte AddDefaultCharset UTF-8 stehen. Das vereint das Charset über HTTP.

PHP/Browser:

Wenn der Browser kein UTF-8 anzeigen will, kann man das im php.ini umstellen: default_charset = “UTF-8″.

Links

http://www.phpwact.org/php/i18n/charsets ist eine wirklich gute, praktische Einführung in das Problem im Zusammenhang mit PHP.

Symfony/Creole:

Um da mit UTF-8 zu arbeiten muss databases.yml gefüllt werden. KEIN dsn benutzen, denn dann funzts nicht:

all:
  modul:
    class:      sfPropelDatabase
    param:
      phptype:  mysql
      username: dbuser
      password: dbuserpass
      database: modul
      host:     localhost
      encoding: utf8

Ein ähnliches, hässliches Problem bei der Datenbankmigration wird bei Orthogonal Thought beschrieben.

Ähnliche Artikel

Eingeordnet in Theorie und Schnipsel | 4 Komentare »

MySQL Views verwenden mit Propel und Symfony

Geschrieben von skaldrom am 13. November 2006

Symfony, das PHP-Framework ist genial. Will man allerdings die Datenbank-Views verwenden, geht das nicht so direkt.

Damit die Propel orm-Klassen generiert werden, muss im config/schema.yml die Struktur so definiert werden, dass sie nicht direkt in die Datenbank abgespitzt wird:

m_my_view:
  _attributes: { phpName: ModulCompleteView, skipSql: true}
  post_id:        {type: integer}
  post_title:     {type: varchar, size: 255}
  post_content:   {type: longvarchar}
  comment_id:     {type: integer}
  comment_content:{type: longvarchar}

Damit die View bei symfony propel-insert-sql erstellt wird, sollte eine Datei im gleichen Verzeichnis erstellt werden in dem auch lib.model.schema.swl ist (normalerweise /data/sql). Wir nennen sie my-view.sql:

CREATE OR REPLACE view m_my_view as
SELECT
  post.id as post_id,
  post.title as post_title,
  post.content as post_content,
  comment.id as comment_id,
  comment.content as comment_content
FROM
  post, comment
WHERE
  comment.post_id=post.id

Und nun nur noch die Datei sqldb.map ergänzen:

my-view.sql=DB-VERBINDUNG

und nun sollts funzen.

Ähnliche Artikel

Eingeordnet in Theorie und Schnipsel | Keine Kommentare »

Geburtstagsliste mit MySQL

Geschrieben von skaldrom am 26. October 2006

DAS zentrale Feature unseres Informationssystem ist eine Geburtstagsliste *gähn*. Ich habe eine Tabelle und möchte nun Geburtstage ab heute mit sql herausselecten. Diese birthday list hat folgende Probleme:

  • Ich kann sie nicht nach Geburtstagen ordnen, weil das Jahr keine Rolle spielt.
  • Ich kann auch nicht DAYOFYEAR verwenden, weil es ein Gnusch mit den Schalttagen gibt.
  • Es muss zyklisch sein, so dass Ende Jahr die Geburtstage vom Januar angezeigt werden.

Nun, die rettende Idee war, das Datum umzufomatieren. Also der 26.10.2006 zum 1026 zu machen und danach zu ordnen. Der Rest ist gna:

SELECT id, name, vorname, geburtsdatum
FROM personen_complete
WHERE geburtsdatum IS NOT NULL
ORDER BY
  IF( DATE_FORMAT(geburtsdatum,'%m%d') >= DATE_FORMAT(CURDATE(),'%m%d'),0,1),
  DATE_FORMAT(geburtsdatum,'%m%d') ASC,
  name, vorname

Ähnliche Artikel

Eingeordnet in Theorie und Schnipsel | Keine Kommentare »