Ich möchte aus MySQL-Datenbank eine Zeile aus einer Tabelle, die Namen, last_name, Bild BLOB enthält retreive, konnte ich bereits das Bild aus der Datenbank retreive und verwenden Sie es in android Apps mit DecodeInoutStrem. aber will nicht nur das bild, ich möchte das bild mit seinem namen und nachname bekommen. wie kann ich das machen ?Wie bekomme ich eine Zeile von MySQL und benutze es in android
dies DoInBackground Methode i Bild über php von mysql zu verwenden retreive (load_image_from_db.php) URL:
@Override
protected Bitmap doInBackground(String... params) {
String add1 = "http://192.168.1.11/save/load_image_from_db.php?id=1";
URL url;
Bitmap image = null;
try {
url = new URL(add1);
HttpURLConnection connection =(HttpURLConnection) url.openConnection();
image = BitmapFactory.decodeStream(connection.getInputStream());
} catch (MalformedURLException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();}
return image;
}
}
load_image_from_db.php
<?php
$con = mysqli_connect("localhost","root","","othmane") or die(mysqli_error($con));
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['id'];
$sql = "SELECT image,image_type FROM images where id = $id";
$r = mysqli_query($con,$sql) or die(mysqli_error($con));;
$result=mysqli_fetch_array($r);
header('Content-Type:image/jpeg');
if ($result['image_type'] == 'php') {
echo ($result['image']);
} else if ($result['image_type'] == 'android') {
echo base64_decode($result['image']);
}
mysqli_close($con);
//stripslashes ($result['image']);
//echo '<img src="data:image/jpeg;base64,'.base64_encode($result['image']).'"/>';
//echo base64_encode($result['image']);
}
?>
Erstellen Sie API in PHP und verwenden Sie dann das zum Abrufen der Daten. – NomanJaved