store images in database

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

store images in database

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: store images in database

Post 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.
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: store images in database

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: store images in database

Post by Celauran »

In what sense? PDO isn't terribly complicated, nor should storing a file path be. Where are you running into problems?
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: store images in database

Post 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>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: store images in database

Post 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?
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: store images in database

Post 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.
Post Reply