Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Use a <code>blob</code> field.</h3> <p>In MySQL, there's a datatype called <code>blob</code>. You can use that to create it.</p> <p>There's a <a href="http://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/" rel="nofollow"><strong>tutorial</strong></a> on how to do that.</p> <h3>Inserting the image into DB:</h3> <pre><code># If no error if($_FILES['userfile']['error']==UPLOAD_ERR_OK) { # Check if the file is uploaded via HTTP POST if(is_uploaded_file($_FILES['userfile']['tmp_name'])) { $imgData = file_get_contents($_FILES['userfile']['tmp_name']); mysqli_connect("localhost", "$username", "$password"); mysqli_select_db ("$dbname"); $sql = "INSERT INTO `users` ( `idimage` ) VALUES ('{$imgData}')"; mysqli_query($sql); } } </code></pre> <h3>Displaying the image from the DB:</h3> <pre><code> &lt;?php if(isset($_GET['id']) &amp;&amp; is_numeric($_GET['id'])) { # Connect to DB $link = mysqli_connect("$hostname", "$username", "$password") or die("Could not connect: " . mysqli_error()); mysqli_select_db("$database") or die(mysqli_error()); # SQL Statement $sql = "SELECT `idimage` FROM `users` WHERE id=" . mysqli_real_escape_string($_GET['id']) . ";"; $result = mysqli_query("$sql") or die("Invalid query: " . mysqli_error()); # Set header header("Content-type: image/png"); echo mysqli_result($result, 0); } else echo 'Please check the ID!'; ?&gt; </code></pre> <h3>It is better to avoid <code>mysql_*</code> functions instead use <code>mysqli_*</code> or <code>PDO</code>.</h3>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload