GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Php/mysql display BLOB field data? (https://gfy.com/showthread.php?t=851116)

acctman 08-28-2008 10:45 AM

Php/mysql display BLOB field data?
 
does anyone know how to display the data that is kept in a BLOB field format? I can only find examples that should how to display an image if saved to BLOB format type but nothing on how to display text.

there should be data for two dropdown menu's and two textbox stored in m_addtn field

<?php

$res = mysql_query("SELECT m_addtn FROM s_viz WHERE m_id = '39'");

$result = mysql_fetch_assoc($res);
echo $result;

?>

GigoloShawn 08-28-2008 10:45 AM

A blob field is usually considered to be binary data.

You're gonna want to escape that.

If you want to display text, you should use TEXT or TINYTEXT and not BLOB for storage.

acctman 08-28-2008 11:43 AM

Quote:

Originally Posted by GigoloShawn (Post 14678134)
A blob field is usually considered to be binary data.

You're gonna want to escape that.

If you want to display text, you should use TEXT or TINYTEXT and not BLOB for storage.

unfortunately this script was coded by someone else, i'm trying to clean up all the problem areas that I find. I need to decode the binary unserialize(base64_decode($result)) didnt work... any suggestions? Once I figure out how to decode and retrieve the data I've setup 4 separate fields in which I plan to populate all current user data too and eliminate the BLOB field

this code below just shows me the encoded info, i need to decode it

$res = mysql_query("SELECT m_addtn FROM s_viz WHERE m_id = '39'");
$result = mysql_fetch_array($res);

echo var_dump($result);

GigoloShawn 08-28-2008 11:49 AM

If it was serialized, it'd likely be base64 encoded afterwards; why it was stored as a blob well, that's kind of dumb. Try print_r($result) to see what's in your array.

Or, you can always:

PHP Code:

foreach ($result as $arg=>$val) {
  echo 
"$arg is $val<br>";


How do you know its base64? Is it terminating with a few =? If not, it may not be base64.

BigBen 08-28-2008 11:57 AM

See how the insert is done and what kind of encoding is being used.

Tempest 08-28-2008 12:47 PM

What bigben said... sometimes you'll compress text data and store it in a blob

HomerSimpson 08-28-2008 12:56 PM

what are you saving in database as blob.
If you are saving whole files (images etc...) in database that's bad so try to avoid that any way you can.

acctman 08-28-2008 12:57 PM

Quote:

Originally Posted by GigoloShawn (Post 14678423)
If it was serialized, it'd likely be base64 encoded afterwards; why it was stored as a blob well, that's kind of dumb. Try print_r($result) to see what's in your array.

Or, you can always:

PHP Code:

foreach ($result as $arg=>$val) {
  echo 
"$arg is $val<br>";


How do you know its base64? Is it terminating with a few =? If not, it may not be base64.

for displaying the data in the script it has <? $en['quests'] = unserialize(base64_decode($en['mm_addtn'])); ?>

with print or echo
Array ( [0] => YTo0OntpOjM7czo4OiJCaXNleHVhbCI7aTo2O3M6ODoiSW52b2 x2ZWQiO2k6NDtzOjIxOiJJIEFEREVEIFNPTUUgTkVXIFBJQ1Mi O2k6MTtzOjI5OiJUSEVZIFIgSU4gVEhFIEVYUExJQ0lUUyA0IE 5PVyI7fQ== [m_addtn] => YTo0OntpOjM7czo4OiJCaXNleHVhbCI7aTo2O3M6ODoiSW52b2 x2ZWQiO2k6NDtzOjIxOiJJIEFEREVEIFNPTUUgTkVXIFBJQ1Mi O2k6MTtzOjI5OiJUSEVZIFIgSU4gVEhFIEVYUExJQ0lUUyA0IE 5PVyI7fQ== )

with foreach statement
0 is YTo0OntpOjM7czo4OiJCaXNleHVhbCI7aTo2O3M6ODoiSW52b2 x2ZWQiO2k6NDtzOjIxOiJJIEFEREVEIFNPTUUgTkVXIFBJQ1Mi O2k6MTtzOjI5OiJUSEVZIFIgSU4gVEhFIEVYUExJQ0lUUyA0IE 5PVyI7fQ==
m_addtn is YTo0OntpOjM7czo4OiJCaXNleHVhbCI7aTo2O3M6ODoiSW52b2 x2ZWQiO2k6NDtzOjIxOiJJIEFEREVEIFNPTUUgTkVXIFBJQ1Mi O2k6MTtzOjI5OiJUSEVZIFIgSU4gVEhFIEVYUExJQ0lUUyA0IE 5PVyI7fQ==

acctman 08-28-2008 01:01 PM

Quote:

Originally Posted by HomerSimpson (Post 14678792)
what are you saving in database as blob.
If you are saving whole files (images etc...) in database that's bad so try to avoid that any way you can.

the m_addtn BLOB field is all test/data... the original coder did it that way. I'm just trying to clean things up. In the end I'll insert the text data in 4 separate fields the way it should of been done originally. First task is to decode the data from the BLOB and retrieve it, then insert into m_status, m_ori, m_turn1 and m_turn2

Varius 08-28-2008 01:18 PM

Quote:

Originally Posted by BigBen (Post 14678471)
See how the insert is done and what kind of encoding is being used.

Yup, this would be how to solve it.

Just find what's done to the text before it's inserted, then reverse that when it comes out. A BLOB field itself doesn't do its own encrypting or anything.

On the small chance there is nothing being done to the data before it's put into the database, check for any Triggers in MySQL as there could be one that ON INSERT or ON UPDATE encrypts the value in that field.

acctman 08-28-2008 01:57 PM

Quote:

Originally Posted by Varius (Post 14678879)
Yup, this would be how to solve it.

Just find what's done to the text before it's inserted, then reverse that when it comes out. A BLOB field itself doesn't do its own encrypting or anything.

On the small chance there is nothing being done to the data before it's put into the database, check for any Triggers in MySQL as there could be one that ON INSERT or ON UPDATE encrypts the value in that field.

this is what it's doing when it processes a update/insert into that field.

$addtn = base64_encode(serialize($_POST['edit_add']));
$q = 'm_addtn="'.$addtn.'"'.$q;

i tried this piece of code (below) but just received a T_String error
print_r unserialize(base64_decode($results));

Varius 08-28-2008 02:04 PM

Quote:

Originally Posted by acctman (Post 14679073)
this is what it's doing when it processes a update/insert into that field.

$addtn = base64_encode(serialize($_POST['edit_add']));
$q = 'm_addtn="'.$addtn.'"'.$q;

i tried this piece of code (below) but just received a T_String error
print_r unserialize(base64_decode($results));

is $results there the array though (recordset returned)? If so that's your error, you need to unserialize(base64-decode()) on the actual string (data of that one field), not the whole returned result (recordset).

if you want paste the few lines of code you have above that where it shows the fetching of the row, etc...

acctman 08-28-2008 02:44 PM

Quote:

Originally Posted by Varius (Post 14679093)
is $results there the array though (recordset returned)? If so that's your error, you need to unserialize(base64-decode()) on the actual string (data of that one field), not the whole returned result (recordset).

if you want paste the few lines of code you have above that where it shows the fetching of the row, etc...

i just tried the code below, I'm getting a blank page this time around. there is two array 0 and m_addtn

$res = mysql_query("SELECT m_addtn FROM s_viz WHERE m_id = '39'");
$result = mysql_fetch_array($res);

$decode = unserialize(base64_decode($results['m_addtn']));
print_r($decode);

GigoloShawn 08-28-2008 03:22 PM

Quote:

Originally Posted by acctman (Post 14679267)
i just tried the code below, I'm getting a blank page this time around. there is two array 0 and m_addtn

$res = mysql_query("SELECT m_addtn FROM s_viz WHERE m_id = '39'");
$result = mysql_fetch_array($res);

$decode = unserialize(base64_decode($results['m_addtn']));
print_r($decode);

Life happened. That is base64, allright.

Looking at the foreach, it said it was a sub-branch [0], so, try:

PHP Code:

$decode unserialize(base64_decode($results['m_addtn']['0']));
print_r($decode); 


GigoloShawn 08-28-2008 03:29 PM

Dammit, I waited too long to edit:

I just saw your very last post.

You're setting $result, and resting $results; otherwise, you're on the right track. No idea why you'd be doing mysql_array("...",MYSQL_BOTH), but, whatever.

jimbona 08-28-2008 03:42 PM

try doing a redecode after youve dumped the array

PHP Code:

foreach ($result as $arg=>$val) { 
  echo 
"$arg is ".base64_decode($val)."<br>\n\n"



Varius 08-28-2008 05:18 PM

as GigoloShawn said above, you are using the variable $results when it is $result heh.

This line should produce what you want:

echo unserialize(base64_decode($result[0][0]));

(feel free to use the field name instead of that second 0 though, to make your code easier to read):

echo unserialize(base64_decode($result[0]['m_addtn']));

acctman 08-28-2008 05:21 PM

Quote:

Originally Posted by GigoloShawn (Post 14679453)
Dammit, I waited too long to edit:

I just saw your very last post.

You're setting $result, and resting $results; otherwise, you're on the right track. No idea why you'd be doing mysql_array("...",MYSQL_BOTH), but, whatever.

thanks for spotting my error, i tried out MYSQL_BOTH works pretty good.

thanks everyone for helping me out

d-null 08-29-2008 12:03 AM

bumping some good expertise

mrkris 08-29-2008 12:44 AM

For future reference,

Code:

<pre><?php print_r($data); ?></pre>
Having it aligned in browser will help you follow nested data structures much easier.


All times are GMT -7. The time now is 05:30 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123