Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich möchte einen String verschlüsseln. Dabei möchte ich nicht die crypt() Funktion von PHP verwenden, sondern ich möchte eine DB-Anfrage an mySql senden, damit der dann ein ENCRYPT ausführt.

Anfrage sollte so sein:

$query = "select ENCRYPT("meinGeheimerString");

Nun möchte ich nach der Ausführung dieses Befehls den verschlüsselten String an meine PHP-Datei zurückgegeben bekommen.

Aber wie bekomme ich von einer mysql_query() das Ergebnis zurück (also den Rückgabewert von mysql)? Denn wenn man das aufruft in mysql, sieht das so aus:

mysql> select ENCRYPT("meinGeheimerString");

-> ihwhöihpo7687hk

und dieses verschlüsselte Gewussel will ich nun an mein PHP-Skript zurückgeben... und ich sehe grad den Wald vor lauter Bäumen nicht... wahrscheinlich ist es ganz einfach... :/

eventuell so:


$result = mysql_query("SELECT ENCRYPT(\"DeinString\") AS string");
print($result["string"]);

// nicht getestet, Hut auf, Hut zu...
[/PHP]

Ciao TinTin

eventuell so:


$result = mysql_query("SELECT ENCRYPT(\"DeinString\") AS string");
print($result["string"]);

// nicht getestet, Hut auf, Hut zu...
[/PHP]

Ciao TinTin

Hmm.. da fehlt IMHO noch was:

[PHP]
$result = mysql_query("SELECT ENCRYPT('Dein String') AS string");
$row = mysql_fetch_array($result);

if ($row !== FALSE)
print $row["string"];

//ebenfalls net getestet :)

Hmm, das hat leider nicht geklappt.

Er gibt dann gar nichts aus... also bleibt leer. :(

Noch n kleinen Tipp vielleicht?! :)

dein code?

vorher ne connection geöffnet?

connection besteht; kann vorherige SELECTs ohne Probs ausführen. Aber nur den einen Schnipsel nicht, den ich jetzt so wie von TinTin und und kleiner_hobbes vorgeschlagen eingefügt.


$result = mysql_query("SELECT ENCRYPT('Dein String') AS string");
if (!$result) {
die('Invalid query: ' . mysql_error());
}

while( $row = mysql_fetch_assoc($result)) {
print $row["string"];
}
[/PHP]

SQL Reference Manual for Version 4.0.5

ENCRYPT(str[,salt])

Encrypt str using the Unix crypt() system call. The salt argument should be a string with two characters. (As of MySQL Version 3.22.16, salt may be longer than two characters.):

mysql> SELECT ENCRYPT("hello");

-> 'VxuFAJXVARROc'

If crypt() is not available on your system, ENCRYPT() always returns NULL. ENCRYPT() ignores all but the first 8 characters of str, at least on some systems. This will be determined by the behaviour of the underlying crypt() system call.

eventuell könnte es ja daran liegen. Probier mal PASSWORD() ...

Ciao TinTin

Mich würde mal interessieren _warum_ du den Query verschlüsseln willst.

Das Skript von Kills hat funktioniert - vielen Dank dafür. :)

Ich brauche das, weil ich Passwörter in die User-Tabelle von mysql einschiebe. Und die sollen gecryptet werden. :)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.