hi friends help me plzzzz
can any once send me a code for to save a image in mysql by a stored procedure in .net
hi friends help me plzzzz
can any once send me a code for to save a image in mysql by a stored procedure in .net
Code:<?php $con=mysql_connect($host,$user,$pass); mysql_select_db($db); if(isset($_REQUEST['submit'])) { $imgtype=$_FILES['uploadfile']['type']; $name=$_REQUEST['name']; if($imgtype=="image/jpeg" || $imgtype=="image/jpg" || $imgtype=="image/pjpeg" || $imgtype=="image/gif" || $imgtype=="image/x-png" || $imgtype=="image/bmp") { $image=$_FILES['uploadfile']['tmp_name']; $fp = fopen($image, 'r'); $content = fread($fp, filesize($image)); $content = addslashes($content); fclose($fp); $sql="insert into table (name,image) values ('$name','$content')"; $res=mysql_query($sql) or die (mysql_error()); } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Test</TITLE> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> </HEAD> <BODY> <form name="form" method="post" ENCTYPE="multipart/form-data" action="image_upload.php"> <table> <tr> <td>Name: <input type="text" name="name"></td> </tr> <tr> <td > Upload image: <input type="file" name="uploadfile"> </td> </tr> <tr> <td><input name="submit" value="submit" type="submit"> </td> </tr> </table> </form> </BODY> </HTML>
Here I will provide you the PHP code using which you could access your Image stored in MySql database:
Code:You could also use some very basic PHP. <?php $conn = mysql_connect(dbhost, dbuser, dbpass) or die ('Unable to connect to database'); mysql_select_db(whatever_you_db_is); $query = "SELECT * FROM tablename"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<img src={$row['image']}>"; } ?>
i want in mysql how can i
To insert an image, you need to establish a connection with MySQL database. Lets' take a database hibernatetutorial, in our case. This database has a table (Image table). For inserting an image in table, we have used the SQL statement “INSERT INTO Image values(?,?,?)” with the prepareStatement() method. Whenever an image is inserted into the database, it displays “Inserting Successfully”. If it fails to insert an image then it throws an exception.
Try to use the following code i am sure it will work for you.
Code:import java.sql.*; import java.io.*; public class insertImage{ public static void main(String[] args) { System.out.println("Insert Image Example!"); String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName = "hibernatetutorial"; String userName = "root"; String password = "root"; Connection con = null; try{ Class.forName(driverName); con = DriverManager.getConnection(url+dbName,userName,password); Statement st = con.createStatement(); File imgfile = new File("images.jpg"); FileInputStream fin = new FileInputStream(imgfile); PreparedStatement pre = con.prepareStatement("insert into Image values(?,?,?)"); pre.setInt(1,5); pre.setString(2,"Durga"); pre.setBinaryStream(3,fin,(int)imgfile.length()); pre.executeUpdate(); System.out.println("Inserting Successfully!"); pre.close(); con.close(); } catch (Exception e){ System.out.println(e.getMessage()); } } }
The code is also attached with this post. You Can Download It From Here
thank for ur reply ,but i need to do in .net
(i,e) i will hv a upload button, where i will browse the image and i will have upload button when i click that button that image has to save in Mysql
how can i
Bookmarks