PSD-Tutorials.de
Forum für Design, Fotografie & Bildbearbeitung
Tutkit
Agentur
Hilfe
Kontakt
Start
Forum
Aktuelles
Besonderer Inhalt
Foren durchsuchen
Tutorials
News
Anmelden
Kostenlos registrieren
Aktuelles
Suche
Suche
Nur Titel durchsuchen
Von:
Menü
Anmelden
Kostenlos registrieren
App installieren
Installieren
JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser
verwenden.
Antworten auf deine Fragen:
Neues Thema erstellen
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
[PHP] mysql_query Problem
Beitrag
<blockquote data-quote="masterb44hz" data-source="post: 929346" data-attributes="member: 250369"><p><strong>AW: [PHP] mysql_query Problem[/b]</strong></p><p><strong></strong></p><p><strong>Kann es wirklich daran liegen? Wird getData() nicht automatisch durch das include-statement aufgerufen, sodass dann die Variable $settings, die ja nach durchlaufen der Funktion getData() zurückgegeben wird, genutzt werden kann?</strong></p><p><strong></strong></p><p><strong>Ich habe nochmal ein bisschen was anderes probiert:</strong></p><p><strong></strong></p><p><strong>[B]createtable.php[/B]</strong></p><p><strong>[CODE]<?php</strong></p><p><strong></strong></p><p><strong>$dbname = "blub"</strong></p><p><strong></strong></p><p><strong>[COLOR=Red]include 'connect.php';[/COLOR] [COLOR=Blue]<= hier gibt es einen "parse error"... warum?[/COLOR]</strong></p><p><strong></strong></p><p><strong> mysql_connect([COLOR=Red]$con[/COLOR]); [COLOR=Blue]<-- Verbindung über connect.php; $con wird wieder aus einer Funktion ausgegeben[/COLOR]</strong></p><p><strong></strong></p><p><strong> mysql_select_db($dbname[COLOR=Red], $con[/COLOR]); [COLOR=Blue]<--vorher war dort keine Verbindung zur Datenbank[/COLOR]</strong></p><p><strong> </strong></p><p><strong> mysql_query("CREATE TABLE pagedata(</strong></p><p><strong> Titel varchar(255) NOT NULL,</strong></p><p><strong> Inhalt text NOT NULL)") or die('Could not create datatable: ' .mysql_error());</strong></p><p><strong></strong></p><p><strong> mysql_close();</strong></p><p><strong>?>[/CODE]</strong></p><p><strong></strong></p><p><strong>[B]connect.php[/B]</strong></p><p><strong>[CODE]<?php</strong></p><p><strong>class connect{</strong></p><p><strong></strong></p><p><strong> var $con;</strong></p><p><strong> </strong></p><p><strong> function connect(){</strong></p><p><strong></strong></p><p><strong> include_once 'data.php';</strong></p><p><strong></strong></p><p><strong> $con = mysql_connect($settings['server'], $settings['user'], $settings['password']);</strong></p><p><strong> if(!$con){</strong></p><p><strong> die('Could not connect: ' .mysql_error());</strong></p><p><strong> } else {</strong></p><p><strong> return $con;</strong></p><p><strong> }</strong></p><p><strong> }</strong></p><p><strong>}</strong></p><p><strong>?>[/CODE]</strong></p><p><strong></strong></p><p><strong>[B]data.php[/B]</strong></p><p><strong>[CODE]<?php</strong></p><p><strong>class Data{</strong></p><p><strong> </strong></p><p><strong> var $settings;</strong></p><p><strong> </strong></p><p><strong> function getData() {</strong></p><p><strong> </strong></p><p><strong> $settings['server']='localhost';</strong></p><p><strong> $settings['user']='admin';</strong></p><p><strong> $settings['password']='admin';</strong></p><p><strong> </strong></p><p><strong> return $settings;</strong></p><p><strong> }</strong></p><p><strong>}</strong></p><p><strong></strong></p><p><strong>?>[/CODE][/PHP]</strong></p></blockquote><p></p>
[QUOTE="masterb44hz, post: 929346, member: 250369"] [b]AW: [PHP] mysql_query Problem[/b] Kann es wirklich daran liegen? Wird getData() nicht automatisch durch das include-statement aufgerufen, sodass dann die Variable $settings, die ja nach durchlaufen der Funktion getData() zurückgegeben wird, genutzt werden kann? Ich habe nochmal ein bisschen was anderes probiert: [B]createtable.php[/B] [CODE]<?php $dbname = "blub" [COLOR=Red]include 'connect.php';[/COLOR] [COLOR=Blue]<= hier gibt es einen "parse error"... warum?[/COLOR] mysql_connect([COLOR=Red]$con[/COLOR]); [COLOR=Blue]<-- Verbindung über connect.php; $con wird wieder aus einer Funktion ausgegeben[/COLOR] mysql_select_db($dbname[COLOR=Red], $con[/COLOR]); [COLOR=Blue]<--vorher war dort keine Verbindung zur Datenbank[/COLOR] mysql_query("CREATE TABLE pagedata( Titel varchar(255) NOT NULL, Inhalt text NOT NULL)") or die('Could not create datatable: ' .mysql_error()); mysql_close(); ?>[/CODE] [B]connect.php[/B] [CODE]<?php class connect{ var $con; function connect(){ include_once 'data.php'; $con = mysql_connect($settings['server'], $settings['user'], $settings['password']); if(!$con){ die('Could not connect: ' .mysql_error()); } else { return $con; } } } ?>[/CODE] [B]data.php[/B] [CODE]<?php class Data{ var $settings; function getData() { $settings['server']='localhost'; $settings['user']='admin'; $settings['password']='admin'; return $settings; } } ?>[/CODE][/PHP][/b] [/QUOTE]
Bilder bitte
hier hochladen
und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Zitate einfügen…
Authentifizierung
Wenn ▲ = 5, ▼ = 2 und ■ = 7, was ist ▲ × ▼ + ■?
Antworten
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
[PHP] mysql_query Problem
Oben