Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases
You last visited: Today at 16:26

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Release] Database (MySQL) Plugin for ETMuS

Discussion on [Release] Database (MySQL) Plugin for ETMuS within the Coding Releases forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2010
Posts: 22
Received Thanks: 35
Cool [Release] Database (MySQL) Plugin for ETMuS

+----------+
| 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
In such case you have to write complex code for abstracting your SQL statements. By using this plugin you can easily create new connections by using
PHP Code:
$newinstance[] = +OutstandDesign+ETMuS+Modules+Database+MySQL(); 
Note: Because \ isn't working inside the [PHP] -Tag I used +. Keep in mind to use a backslash (\)

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"
If you want to reuse some informations (for example an identical database) clone the created object:
PHP Code:
$newinstance[] = clone $newinstance[0]; 
The cloned object holds now the same informations as the first instance. We now manipulate some variables:
PHP Code:
$newinstance[1]->IP "127.0.0.1";
$newinstance[1]->Prefix "woot_";
$newinstance[1]->Postfix "_foo"
Lets say $newinstance[0] is server 1 and $newinstance[1] is our server 2. If you want to have a command executed on both servers you can use this code:
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));

$sql would have this value:
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 ....."); 
A full documented list of methods and properties can be found here:

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
In diesen Fällen müsste man eine recht complexen code schreiben, um diese SQL statements zu vereinfachen.
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(); 
Note: Bitte beachtet, dass ich statt dem \ ein + nehmen musste, da das [PHP]-Tag keine \ aktzeptiert/sie entfernt.

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"
Falls ihr bestehende Informationen wiederverwenden wollt (z.B. bei einer 2. Datenbank), kopiert am besten das bestehende Objekt:
PHP Code:
$newinstance[] = clone $newinstance[0]; 
Das kopierte Objekt enthält alle Eigenschaften des Ursprungsobjekts. Ändern wir einige der Daten:
PHP Code:
$newinstance[1]->IP "127.0.0.1";
$newinstance[1]->Prefix "woot_";
$newinstance[1]->Postfix "_foo"
Nehmen wir an, $newinstance[0] ist Server 1 und $newinstance[1] ist unser Server 2. Falls nun ein SQL-Befehl auf beiden Servern ausgeführt werden soll, kann man folgendes Snippet nutzen:
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));

$sql hat dabei folgende Werte:
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 ....."); 
Eine ausführliche Dokumentation aller Methoden und Eigenschaften kann hier gefunden werden:

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
M2Commander is offline  
Reply

Tags
etmus mysql script


Similar Threads Similar Threads
[Release] ETMuS - Simple template system
05/05/2012 - Coding Releases - 2 Replies
+----------+ | English | +----------+ Hi all, I am proud to release my third work now: ETMuS - Extendable Template Markup Script. I will also publish some plugins for this release soon. Those will include a plugin for MySQL and MSSQL database connections. I started this project quite a while ago and was always extending it and adding some features. I hope that this script helps someone out there to create complex sites with a low cost of time building up the base for it. It was...
MySql 5.1 Or Database Or Source
05/04/2012 - CO2 Private Server - 7 Replies
I Have Problem At My Server Just Happened From 3 Days the problem is Disconnect at my Server Can't login and Can't exit like i open FireWall at My Network i don't have any Error to know problem i'm Use MySql 5.1 For Database anyone know what this problem>?
Hello i need help with a registration for mysql database
11/20/2010 - General Gaming Discussion - 0 Replies
just what the title says i have this new server and i wanna make a site for it for easeir registration
[HELP] MySql Database
12/09/2008 - CO2 Private Server - 0 Replies
Mysql database keeps giving an error: PHPMYADMIN ERROR, The server isn't reacting. What should i do lol, i've re-installed it like 3 times still doesn't work. Hm... Ciao!
'' MySQL database ''
11/10/2008 - Conquer Online 2 - 8 Replies
How do i let my friend connect to my MYSQL database so he can also be a hoster and create accounts. Any 1 idea's post em here Regards Memos ,



All times are GMT +1. The time now is 16:26.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.