Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.02.06 08:57 
Hallo,

ich habe mich gestern mit diesem Tutorial beschäftigt:
--> www.luckie-online.de...QL_mit_Delphi_01.php

Mein bisheriger Code sieht so aus:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
uses mysql;

var
 Descriptor: PMYSQL;

function Connect(Descriptor: PMYSQL; const Host, User, PW, DB: string; Port:
  Integer): PMYSQL;
begin
  result := mysql_real_connect(Descriptor, PChar(Host), PChar(User), PChar(PW),
  PChar(DB), PORT, nil, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Descriptor := mysql_init(nil);
Descriptor := Connect(descriptor,'<censored>','<censored>','<censored>','<censored>',3306);
if Assigned(Descriptor) then
begin
showmessage('Verbunden');
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
query: String;
  ErrorCode: Integer;
begin
  query := 'CREATE DATABASE' + ' ' + edit1.text;
  ErrorCode := mysql_real_query(Descriptor, PChar(query), length(query));

end;

Die DLL liegt auch im Programmverzeichnis (@Luckie: Die Antwort auf deine PN ;) ) Die Anwendung startet schon mal ohne Fehler :-)
Allerdings beim Klick auf Button1 bekomm ich das:
Zitat:

---------------------------
Benachrichtigung über Debugger-Exception
---------------------------
Im Projekt SMS_Server.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 10004CD7 in Modul 'libmysql.dll'. Lesen von Adresse 00000000'. Prozeß wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen.
---------------------------
OK Hilfe
---------------------------

Die Paramter von connect habe ich hier natürlich entfernt.
Wie kann ich nun eine Datenbank anlegen? Ich bin hier grad in der Schule und sitze hinter einem Proxy-Server, vlt. könnte das ein Grund sein :nixweiss: .
Ansonsten bin ich ratlos :-(

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Fr 24.02.06 10:17 
Wird denn auch ein "Verbunden" (Zeile 19 in Deinem Sourcecode) beim Programmstart angezeigt?

_________________
Ein Nutzer der Ecke ;-)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.02.06 14:27 
Nein, wird es nicht.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Fr 24.02.06 14:32 
Du solltest bevor du eine Query startest, auch überprüfen, ob die Datenbankverbindung erfolgreich aufgebaut wurde. Wahrscheinlich weil du hinter dem Proxy sitzt, schlägt mysql_real_connect fehl und liefert nil zurück. Dann machst du mysql_real_query mit nil als Descriptor und das führt zur Zugriffsverletzung.

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.02.06 16:03 
Wäre möglich, aber zuhause klappt es auch nicht. :-(
Was mache ich beim Herstellen der Verbindung falsch?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Fr 24.02.06 16:15 
Das sieht für mich erstmal alles richtig aus. Wahrscheinlich musst du einfach mal die MySQL Dokumentation konsultieren - das MySQL-API hat garantiert auch eine Funktion um Fehlercodes oder Fehlertexte zu ermitteln. Die kannst du aufrufen, wenn mysql_real_connect nil zurückgibt um rauszufinden, was schiefgelaufen ist.

Kommst du denn mit anderen Programmen, z.B irgendwelchen MySQL-Verwaltungstools auf die Datenbank? Vielleicht stimmen ja die Verbindungsparameter nicht.
Läuft die Datenbank bei einem Internet-Provider? Einige davon, z.B. Strato sperren als Sicherheitsmaßnahme externen Zugriff auf MySQL-Datenbanken, die auf ihren Servern laufen.

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.02.06 22:48 
user profile iconStefan.Buchholtz hat folgendes geschrieben:
Wahrscheinlich musst du einfach mal die MySQL Dokumentation konsultieren - das MySQL-API hat garantiert auch eine Funktion um Fehlercodes oder Fehlertexte zu ermitteln.

Wo find ich sowas? :?: :nixweiss:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.02.06 22:57 
Ich das hier gefunden:
dev.mysql.com/doc/re.../de/mysql-error.html
Aber wenn ich es so versuche:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage((mysql_error(descriptor)));
end;

Dann bekomm ich wieder ne Zugriffsverletzung :motz:
--------------------------------------------------------------------------------------------------------
Hier habe ich eine Liste mit Fehlercodes gefunden:
dev.mysql.com/doc/re...ql-real-connect.html

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 26.02.06 10:26 
*push*
Hat niemand eine Idee? :-(

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 26.02.06 10:31 
user profile iconStefan.Buchholtz hat folgendes geschrieben:
Das sieht für mich erstmal alles richtig aus. Wahrscheinlich musst du einfach mal die MySQL Dokumentation konsultieren - das MySQL-API hat garantiert auch eine Funktion um Fehlercodes oder Fehlertexte zu ermitteln. Die kannst du aufrufen, wenn mysql_real_connect nil zurückgibt um rauszufinden, was schiefgelaufen ist.

Kommst du denn mit anderen Programmen, z.B irgendwelchen MySQL-Verwaltungstools auf die Datenbank? Vielleicht stimmen ja die Verbindungsparameter nicht.
Läuft die Datenbank bei einem Internet-Provider? Einige davon, z.B. Strato sperren als Sicherheitsmaßnahme externen Zugriff auf MySQL-Datenbanken, die auf ihren Servern laufen.

Stefan

das wäre ne idee :idea:

bzw das problem
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 26.02.06 10:33 
Ich hab ja schon versucht, mit mysql_error mir die Fehlermeldung anzuzeigen ;) siehe oben.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 26.02.06 10:34 
mach das ganze doch über ein php skript, dann gehts auf jeden fall

oder soll da jeder user seine eigene datenbank benutzen können ?

naja würde ich trotzdem mit php machen
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 26.02.06 10:37 
Es soll von Delphi aus auf ein MySQL Datenbank auf einem (nicht lokalen) Webserver zugegriffen werden. Ich will Werte aus dieser DB auslesen und in einem Delphi-Programm weiterverarbeiten.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 26.02.06 10:38 
die datenbank ist aber immer die gleiche ?
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 26.02.06 10:43 
Ja, es ist nur eine DB. Und wie muss ich mir das mit PHP jetzt vorstellen. Ich kann mit PHP aus DBs lesen, aber was hat das mit Delphi zu tun bzw. wo ist dort die Schnittstelle, um die Daten mit einem Delphi-Programm zu verarbeiten?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 26.02.06 10:46 
du sendest daten per post mit idhttp an das skript so kannst du was eintragen oder dir auch sachen ausgeben lassen, indem du die ausgabe des skriptes nimmst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  Params: TIdMultiPartFormDataStream;
begin
  Params := TIdMultiPartFormDataStream.Create;
  Params.AddFormField('authid', '4567895648');
  Params.AddFormField('Username', nuser);
  Params.AddFormField('Value', inttostr(nvalue));
  idHTTP.Post('http://bla.de/insert.php', Params);
  FreeAndNil(Params);
end;

ausblenden insert.php
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
<?php
  mysql_connect('localhost', 'user', 'pass');
  mysql_select_db('db');
  if ($_POST['authid'] = '4567895648')
  {
    $Username = $_POST['Username'];
    $Value = $_POST['Value'];
    $Username = stripslashes($username);
    if (($Username != '') && ($Value != '')) //geht auch empty aber egal ^^
# if (!empty($Username) && !empty($Value)) //so zB musst mal testen
      mysql_query("INSERT INTO Highscore (Username, Value) VALUES ('".$Username ."', '".$Value."')");
  }
?>

authid ist nur ein kleines sicherheitsfeature, damit net jeder irgendwas hinsenden kann, man muss eben den code kennen ;) php skript ist net das schönste, aber du bekommst das besser hin ;)


Zuletzt bearbeitet von F34r0fTh3D4rk am So 26.02.06 11:01, insgesamt 3-mal bearbeitet
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 26.02.06 10:51 
Danke - schau ich mir mal an :-)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 26.02.06 10:51 
ja :lol: guckst du oben