| English |
+----------+
Hello everybody,
I will now publish the first plugin for ETMuS. It also can be used without ETMuS so you don't have to use the hole script environment if you don't like it.
Requirements:
- bcompiler
- PHP 5.3 or higher
This plugin helps creating database connections with a hugh abstraction layer. If you have 2 database connections (for example 2 servers) you will probably have the following problems:
- maybe 2 different databases (IP, login credentails)
- if on one server: different post or prefixes either on your databasename or tablename
PHP Code:
$newinstance[] = +OutstandDesign+ETMuS+Modules+Database+MySQL();
Now you can set the settings for your new instance:
PHP Code:
$newinstance[0]->IP = "localhost";
$newinstance[0]->User = "Test";
$newinstance[0]->Password = "Test";
$newinstance[0]->Prefix = "foo_";
$newinstance[0]->DB = "bar";
$newinstance[0]->Postfix = "_woot";
$newinstance[0]->TablePrefix = "bar0_";
$newinstance[0]->TablePostfix = "_0foo";
PHP Code:
$newinstance[] = clone $newinstance[0];
PHP Code:
$newinstance[1]->IP = "127.0.0.1";
$newinstance[1]->Prefix = "woot_";
$newinstance[1]->Postfix = "_foo";
PHP Code:
foreach($newinstance as $server)
{
$sql = "SELECT * FROM ".$server->Prefix.$server->DB.$server->Postfix.".".$server->TablePrefix."hello".$server->TablePostfix." WHERE id=23";
var_dump($server->Select($sql));
}
1. iteration: SELECT * FROM foo_bar_woot.bar0_hello_0foo WHERE id=23
2. iteration: SELECT * FROM woot_bar_foo.bar0_hello_0foo WHERE id=23
You can also create a list with each serverinformations and pick out a specific server and assign the informations to a global var which is used in your scripts.
PHP Code:
$playerdb = $newinstance[1]; #now server 2 is selected
$playerdb = $newinstance[0]; #now server 1 is selected
...
$playerdb->Exec("UPDATE .....");

You can download it here:

You can ask me here or in skype if you have any questions. I can help you also in building up a new webpage if you have any problems.
+-----------+
| Deutsch |
+-----------+
Hallo zusammen,
ich möchte euch hiermit mein 1. Plugin für ETMuS vorstellen. Ihr könnt es auch seperat nutzen, falls das ETMuS script euch nicht zusagt oder aus anderen Gründen.
Vorraussetzungen:
- bcompiler
- PHP 5.3 oder höher
Dieses Plugin soll euch dabei unterstützen, eine Datenbankverbindung herzustellen, und gleichzeitig eine möglichst große Verallgemeinerung bieten. Dies soll dazu dienen, dass ihr folgende Probleme in größeren Skripts lösen könnt:
- bei 2 unterschiedlichen Servern: verschiedene IPs/Logindaten
- falls ein Server: Unterschiedliche Datenbanknamen/ Präfixe/Suffixe von Datenbank oder Tabelle
Durch dieses plugin lassen sich neue Verbindung schnell realisieren. Durch diesen Befehl wird eine "leere" Instance erstellt
PHP Code:
$newinstance[] = +OutstandDesign+ETMuS+Modules+Database+MySQL();
Nun können die Eigenschaften der Instanz gesetzt werden:
PHP Code:
$newinstance[0]->IP = "localhost";
$newinstance[0]->User = "Test";
$newinstance[0]->Password = "Test";
$newinstance[0]->Prefix = "foo_";
$newinstance[0]->DB = "bar";
$newinstance[0]->Postfix = "_woot";
$newinstance[0]->TablePrefix = "bar0_";
$newinstance[0]->TablePostfix = "_0foo";
PHP Code:
$newinstance[] = clone $newinstance[0];
PHP Code:
$newinstance[1]->IP = "127.0.0.1";
$newinstance[1]->Prefix = "woot_";
$newinstance[1]->Postfix = "_foo";
PHP Code:
foreach($newinstance as $server)
{
$sql = "SELECT * FROM ".$server->Prefix.$server->DB.$server->Postfix.".".$server->TablePrefix."hello".$server->TablePostfix." WHERE id=23";
var_dump($server->Select($sql));
}
1. Durchlauf: SELECT * FROM foo_bar_woot.bar0_hello_0foo WHERE id=23
2. Durchlauf: SELECT * FROM woot_bar_foo.bar0_hello_0foo WHERE id=23
Falls man nur eine Verbindungsinformation für die Skriptausführung braucht, kann man aus einer Liste von Verbindungsinformationen eine heraussuchen und diese z.B. einer globalen Variable zuweisen, welche im weiteren Verlauf des Skripts genutzt wird:
PHP Code:
$playerdb = $newinstance[1]; #jetzt ist Server 2 gewählt
$playerdb = $newinstance[0]; #jetzt ist Server 1 gewählt
...
$playerdb->Exec("UPDATE .....");

Die Daten können hier gefunden werden:

Falls ihr Fragen habt, bin ich natürlich per Skype oder hier direkt verfügbar. Ich kann euch natürlich bei Problemen mit der Erstellung eurer eigenen Webseite helfen.
M2Commander







