The bit that fascinated me was the stuff about how the brain works with associative links, not linearly. Much like the web - jumping about between thoughts and ideas. This led on to their experiment to try and see how the web is affecting our brains (Web Behaviour Experiment), and classifying users based on how they acquire knowledge through the Internet - are you fast or slow, do you read everything - or just enough to make the next jump?
I, apparently, am a Web Fox: fast-moving, sociable and adaptable. This is what most teenagers seem to be these days. And I'm happy with this result.
I like to think that I acquire enough knowledge on my travels to know who, or where, to go next time I need to know something around that topic - without actually having to know it myself. This is the relating to the connectivism theory of learning, it's all about building your networks. And it usually stands me in very good stead.
Today however, I spent far longer than was necessary trying to write a few lines of code to display an image file from a database BLOB (sorry, the technical bits don't really matter to the thread of the story here!). The thing is, I'm now so reliant on my ability to access php.net, Google etc, that I don't even try and recall any knowledge I may already have and write code myself. So I spent ages googling for code examples of the thing I wanted to do - assuming, as usual, that it was out there for the taking. In this case it wasn't. I'd made a fundamental mistake (doing the wrong type of Oracle query) so the bits of code I did find didn't work. I needed someone to spell out the whole darn thing for me...and Google couldn't help.
Eventually of course I started from scratch and built up the code again from bits I properly understood and then it all worked. For those that do want to pull image blobs from an Oracle database and display them in PHP I'll put the code below anyway (so Google will hopefully help the next person).
So lesson learned, start with what I know and understand - and then use my network and Google to build on that. Don't expect them to do all the work for me.
---
Technical stuff
Images need to be seen as separate files with the right file types, so create a file called photo.php like this:
--open php--header("Content-type: image/jpeg");
$id= $_REQUEST['id'];
include ('connect_to_your_database_stuff.php');
$sql = "select * from your_table where photo_field_id = '$id'";
$stmt = oci_parse($conn, $sql);
oci_execute($stmt)
or die ("Unable to execute query\n");
while ( $row = oci_fetch_assoc($stmt) ) {
print $row['IMAGE']->load()."\n";
}
include ('close_your_database_connection.php');
exit;
--close php--
Then you need to call this as if you were loading the jpg directly, ie:
in the page where you want to display your photo.
4 comments:
I'm clearly not used to putting code snippets into blog posts as it's trying to process them instead of displaying the text...sorry!
Please please please change the second line to:
$id = (int) $_REQUEST['id'];
Or better yet, (int) $_GET['id']; or $_POST['id']; depending on how your script will take in input. At the very least, though, unsanitizing inputs before they hit your database could lead to SQL injections and other funfun security issues.
cheers Ben - an unintended consequence of my post, I become a less vulnerable coder! Will leave the dodgy version here so comments make sense, but promise to fix the production code!
Cool. Always happy to help! :)
Post a Comment