vendredi 18 septembre 2015

retrieving data from mysql database and inserting into sqlite and displaying in the imageview

I have a set of images with names.I have created image table with two columns in mysql. I am inserting the images to mysql database using the following code.

if(getimagesize($_FILES['image']['tmp_name']) == FALSE)
            {
                echo "<script>alert('Please select an image')</script>";
            }           
        else 
            {
                $image= addslashes($_FILES['image']['tmp_name']);
                 $name=$productname;
                $image= file_get_contents($image);
                $image= base64_encode($image);
                $qry="insert into images (products,image) values ('$name','$image')";
                $result=mysql_query($qry,$con);
            }

For retreiving and displaying the inserted images i am using the following code.

while($row = mysql_fetch_array($result))
            {

                 $productname = $row['products'];
                echo '<tr align="center" height="70">';
                echo '<td>';
                echo $row[0];
                echo '</td>';
                echo '<td>';
                echo '<img height="200" width="200" src="data:image;base64,'.$row[1].' "> ';
                echo '</td>';
                print("<td width='100'><a href='imagedelete.php?id=$row[products]'>Delete</a></td></tr>");

            } 

Inserting and displaying the all the images are happening correctly using the mysql database.

I tried this code to insert and retrieve and display using sqlite but didnt work.

SQLiteDatabase database = this.getWritableDatabase();
String q="SELECT image FROM Product_Image where products='" + productitem + "'";
Cursor cursor = database.rawQuery(q, null);
cursor.moveToFirst();
byteImage2 = cursor.getBlob(2);
productimage.setImageBitmap(BitmapFactory.decodeByteArray(byteImage2,0, byteImage2.length));

My doubts is

  1. I want to retrive the images from the mysql database and insert to sqlite database.How will i do that.
  2. After inserting i want to retrieve the image from sqlite database and display in the image view.How will i do this.

Please help.Code for my doubts would be helpful.

Aucun commentaire:

Enregistrer un commentaire