Page 1 of 1
store images in database
Posted: Thu Jul 17, 2014 9:56 am
by terrenuit
Hi, I want to store images in my database,
parameter in longblob, binairy, follow the same as this tutorial:
https://www.youtube.com/watch?v=HIAxRMklJww
finally, the tutorial can show the image, not me,
the output shows the wrong codes as:
cç\çµÌ´\Â×ú-ÛË›£šãü”ïô<xx½Ãþ*....
can somebody help me ? please
Re: store images in database
Posted: Thu Jul 17, 2014 10:15 am
by Celauran
Storing images in the DB is generally a really bad idea. Store images in the file system and a reference to them in the DB.
Re: store images in database
Posted: Fri Jul 18, 2014 8:12 am
by terrenuit
it's not easy to find the PHP PDO scripte to display the images,
and the path to link the image is not easy
Re: store images in database
Posted: Fri Jul 18, 2014 8:17 am
by Celauran
In what sense? PDO isn't terribly complicated, nor should storing a file path be. Where are you running into problems?
Re: store images in database
Posted: Fri Jul 18, 2014 1:37 pm
by terrenuit
my scripte PHP PDO is ok for the columns 'name' and ' message', but photo is not ok,
I think the problem is linking the image source,
I followed this tutorial to lonk the source, but it didn't work,
https://www.youtube.com/watch?v=aFiiX2799Vo
Code: Select all
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'testebase';
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sql = 'SELECT name,
photo,
message
FROM trybase';
$q = $conn->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $pe) {
die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP MySQL Query Data Demo</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div id="container">
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>name</th>
<th>photo</th>
<th>message</th>
</tr>
</thead>
<tbody>
<?php while ($r = $q->fetch()): ?>
<tr>
<td><?php echo htmlspecialchars($r['name'])?></td>
<td><img src=<?php echo htmlspecialchars($r['photo']); ?> height="183" width="275"></td>;
<td><?php echo htmlspecialchars($r['message']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
Re: store images in database
Posted: Fri Jul 18, 2014 1:47 pm
by Celauran
What do you mean by 'photo is not OK'? Where are you storing your images? What are you storing as the image path? What is being returned by your query?
Re: store images in database
Posted: Sat Jul 19, 2014 12:08 am
by terrenuit
I store the image in a file,for exemple. the name of image is "boat",
insert the file/boat in the database,
I d'ont know how to build the link for file/boat,
the display is a signal without image(a little cross).
usually by the browser, we can link the file/boat,
but in the database is not in this case, I think.