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: Di 02.01.07 22:16 
Wie kann ich nach einem mysql_query überprüfen, ob dieser erfolgreich war? Er kann ja z.B. Syntaxfehler enthalten. Ich habe keine entsprechende Funktion gefunden, die mir true/false zurückgibt.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot


Zuletzt bearbeitet von Marco D. am Di 02.01.07 22:19, insgesamt 1-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 02.01.07 22:18 
Das gibt dir die Funktion zurück. Wenn die Query nicht erfolgreich war, dann gibt die Funktion FALSE zurück...
Siehe Doku: de.php.net/mysql_query

// EDIT:
BTW: Ich kannte die Funktion nicht und hab das in ein paar Sekunden bei Google gefunden... :roll:
// EDIT2:
Erstes Suchergebnis. Und dort gibts auch ein Beispiel...


Zuletzt bearbeitet von jaenicke am Di 02.01.07 22:21, insgesamt 3-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 02.01.07 22:20 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
$sql = mysql_query('Do Something');

if (!$sql) {
   $message  = 'Invalid query: ' . mysql_error() . "\n";
   $message .= 'Whole query: ' . $query;
   die($message);
}

Aber eigentlich sollest du error_reporting(E_ALL (| E_STRICT)*); aktiviert haben, dann bekommst du auch alle Fehler angezeigt.

*ab PHP 5.0


EDIT: GRML. Wieso bist du grundsätzlich schneller? Wird man das, wenn man älter wird? :mrgreen:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)


Zuletzt bearbeitet von GTA-Place am Di 02.01.07 22:25, 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: Di 02.01.07 22:21 
user profile iconjaenicke hat folgendes geschrieben:
Das gibt dir die Funktion zurück. Wenn die Query nicht erfolgreich war, dann gibt die Funktion FALSE zurück...
Siehe Doku: de.php.net/mysql_query

Hatte bei selfphp.de geguckt und da stand nichts von false. Nur dass der Rückgabewert 'resource' ist. :roll:

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

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 02.01.07 22:22 
user profile iconMarco D. hat folgendes geschrieben:
user profile iconjaenicke hat folgendes geschrieben:
Das gibt dir die Funktion zurück. Wenn die Query nicht erfolgreich war, dann gibt die Funktion FALSE zurück...
Siehe Doku: de.php.net/mysql_query

Hatte bei selfphp.de geguckt und da stand nichts von false. Nur dass der Rückgabewert 'resource' ist. :roll:

Ja? Wo? :lol: // EDIT: Ach ja, bei SelfPHP, ok, überlesen... Das Zitat ist aus dem Manual...
Zitat:
Return Values
For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error.


Zuletzt bearbeitet von jaenicke am Di 02.01.07 22:29, insgesamt 2-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 02.01.07 22:24 
Merke: Das Manual ist grundsätzlich zuerst zu beachten, denn nur das wurde von den "Profis" selbst erstellt.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
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: Di 02.01.07 22:28 
Selfphp:
resource mysql_query ( string Anfrage [, resource Verbindungs-Kennung] )

Aber weiter unten stehts dann doch, habe nur die Definition angeschaut. Dann hätte dort aber auch was von bool stehen müssen. :roll:

user profile iconGTA-Place hat folgendes geschrieben:
Merke: Das Manual ist grundsätzlich zuerst zu beachten, denn nur das wurde von den "Profis" selbst erstellt.

Ja, stelle ich auch gerade fest.

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

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 02.01.07 22:32 
user profile iconMarco D. hat folgendes geschrieben:
resource mysql_query ( string Anfrage [, resource Verbindungs-Kennung] )

Aber weiter unten stehts dann doch, habe nur die Definition angeschaut. Dann hätte dort aber auch was von bool stehen müssen. :roll:

Ich vermute, dass die gedacht haben, das sei klar. Denn das ist ja üblich bei PHP, das so zu machen. ;-)
Das ist allerdings etwas schwach, dass dort nicht alle möglichen Rückgabewerte aufgelistet stehen. Egal, Hauptsache es steht im Manual. (Und Hauptsache, das Ergebnis im Manual wird als erstes bei Google gefunden. ;-))
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: Di 02.01.07 22:38 
user profile iconjaenicke hat folgendes geschrieben:
user profile iconMarco D. hat folgendes geschrieben:
resource mysql_query ( string Anfrage [, resource Verbindungs-Kennung] )

Aber weiter unten stehts dann doch, habe nur die Definition angeschaut. Dann hätte dort aber auch was von bool stehen müssen. :roll:

Ich vermute, dass die gedacht haben, das sei klar. Denn das ist ja üblich bei PHP, das so zu machen. ;-)
Das ist allerdings etwas schwach, dass dort nicht alle möglichen Rückgabewerte aufgelistet stehen. Egal, Hauptsache es steht im Manual. (Und Hauptsache, das Ergebnis im Manual wird als erstes bei Google gefunden. ;-))

Ok, dann danke ich für deine Hilfe. :zwinker:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 02.01.07 22:40 
Und mir nicht? :lol:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
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: Di 02.01.07 22:48 
user profile iconGTA-Place hat folgendes geschrieben:
Und mir nicht? :lol:

Ja, dir natürlich auch! :mrgreen:

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

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 08.01.07 20:44 
Bliebe allerdings noch die Frage, wie das für UPDATE, DELETE, INSERT, DROP, CREATE * ALTER usw. gehandhabt wird ...

Dazu hab ich bisher nichts eindeutiges gefunden ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.