# Bootstrap.php und MySQL

**URL:** <https://forum.shopware.com/t/bootstrap-php-und-mysql/14651>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [27. Juli 2013 um 13:21 UTC](https://forum.shopware.com/t/bootstrap-php-und-mysql/14651 "2013-07-27T13:21:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattes80](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mattes80](https://forum.shopware.com/u/mattes80)\
**Post date:** [27. Juli 2013 um 13:21 UTC](https://forum.shopware.com/t/bootstrap-php-und-mysql/14651/1 "2013-07-27T13:21:37Z")

</div>

Hallo Ich möchte mein Übungsplugin [http://wiki.shopware.de/Getting-Started … 6\_866.html](http://wiki.shopware.de/Getting-Started%5C_detail%5C_966%5C_866.html) weiter ausbauen. und zwar möchte ich die slogen in einer DB abspeichern ` public $slogans = array( 'Nur ein toter Bug ist ein guter Bug!', 'Smarty is keine Schokolinse!', 'Ein Zend ist kein Geldstück!' );` Die Tabelle name nenne ich einfach Mattes\_slogen\_test Es soll die Tabelle erstellt werden ID | slogenname Normal sollte es so gehen ` $sql = " CREATE TABLE `Mattes_slogen_test` ( `id` INT( 10 ) NOT NULL AUTO\_INCREMENT PRIMARY KEY , `slogenname` TEXT( ) NOT NULL , ) ENGINE = MYISAM ; "; ` Wie fügen ich sowas am besten in `public function install()` und wie frage ich in Shopware die DB wieder ab? gruß Mattes

---

<div class="post-metadata">

**Author:** ![mrtee](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@mrtee](https://forum.shopware.com/u/mrtee)\
**Post date:** [27. Juli 2013 um 14:18 UTC](https://forum.shopware.com/t/bootstrap-php-und-mysql/14651/2 "2013-07-27T14:18:37Z")

</div>

Hallo Mattes, also deinen Query kannst du in der install() wie folgt absetzen. `public function install() { $qry = 'CREATE QUERY HERE'; Shopware()-\>Db()-\>query($qry); } ` Aber schau doch einfach mal in diesen Teil zur Erweiterung des “Slogan des Tages”. Da wird dies auch beschrieben und erläutert. [http://wiki.shopware.de/Shopware-4-Grun … 1\_867.html](http://wiki.shopware.de/Shopware-4-Grundlagen-der-Plugin-Entwicklung%5C_detail%5C_971%5C_867.html) Viele Grüße und viel Erfolg, mrtee

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)\
**Post date:** [27. Juli 2013 um 14:33 UTC](https://forum.shopware.com/t/bootstrap-php-und-mysql/14651/3 "2013-07-27T14:33:01Z")

</div>

Ich habe das Beispiel Plugin mal angepasst. Ist nicht getestet sollte aber funktionieren: [code]\<?php class Shopware\_Plugins\_Frontend\_SwagSloganOfTheDay\_Bootstrap extends Shopware\_Components\_Plugin\_Bootstrap  
{  
public $slogans = array();

```
public function install()
{
    $this->subscribeEvent( 'Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Index', 'onPostDispatchIndex' ); $sql = " CREATE TABLE IF NOT EXISTS `mattes_slogen_test` ( `id` int(11) NOT NULL AUTO\_INCREMENT, `slogenname` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO\_INCREMENT=2 DEFAULT CHARSET=latin1; "; Shopware()-\>Db()-\>query($sql); foreach ($this-\>slogans as $slogan){ Shopware()-\>Db()-\>query('INSERT INTO mattes\_slogen\_test (slogenname)VALUE(:slogan)',array(":slogan"=\>$slogan)); } return true; } public function uninstall() { Shopware()-\>Db()-\>query('DROP TABLE IF EXISTS `mattes_slogen_test`;'); return true; } public function onPostDispatchIndex(Enlight\_Event\_EventArgs $arguments) { /\*\*@var $controller Shopware\_Controllers\_Frontend\_Index \*/ $controller = $arguments-\>getSubject(); $view = $controller-\>View(); $this-\>slogans = Shopware()-\>Db()-\>fetchCol('SELECT slogenname FROM mattes\_slogen\_test'); //Add our plugin template directory to load our slogan extension. $view-\>addTemplateDir($this-\>Path() . 'Views/'); $view-\>extendsTemplate('frontend/plugins/slogan\_of\_the\_day/index.tpl'); $view-\>assign('slogan', $this-\>getRandomSlogan()); } private function getRandomSlogan() { //get random number between 0 and the count of our slogans $index = rand(0, count($this-\>slogans) - 1); return $this-\>slogans[$index]; } }[/code]
```
