Connecting Tech Pros Worldwide Help | Site Map

Retrieving and Formatting a Blob Object

Bob Kaku
Guest
 
Posts: n/a
#1: Jul 17 '05
I've created a MySQL database to store a large amount of text. Since
the text data type in MySQL is limited to 255 characters, I added a
BLOB column. I created an PHP input screen to enter the large text.
It seems to work. But, I cannot verify the entry, because the
standard select SQL does not display the contents. I want to
retrieve the contents from the database and display on a web page.
The retrieval seems to occur. But, I can't display the results,
because I must not be done the proper conversion from BLOB to ordinary
text.

Can somebody help me resolve this problem?

Here is the insert code I'm using.

$newtext = addslashes($blob);
@ $db = mysql_connect('localhost', '<database>', '<password>');
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
mysql_select_db("<database>");
$query = "insert into blog values ('$newtext')";
$result = mysql_query($query);

if ($result)
{
echo mysql_affected_rows()." text item inserted into
database.";
}

Here is the retrieval code I'm using.

$query = "select blogtext from blog";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$blog = $row['blogtext'];
$wraptext = wordwrap($blog, 80, "\n", 1);
echo $wraptext;
}

It displays nothing on my page.

Thanks in advance.
Geoff Berrow
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Retrieving and Formatting a Blob Object


I noticed that Message-ID:
<e48ec4c8.0403181947.1369617f@posting.google.com > from Bob Kaku
contained the following:
[color=blue]
> $query = "insert into blog values ('$newtext')";[/color]

$query = "insert into blog (blogtext) values ('$newtext')";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Bob Kaku
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Retrieving and Formatting a Blob Object


Geoff Berrow <blthecat@ckdog.co.uk> wrote in message news:<559l501vmf5l9olv0s0n90ui1fei25b6nm@4ax.com>. ..[color=blue]
> I noticed that Message-ID:
> <e48ec4c8.0403181947.1369617f@posting.google.com > from Bob Kaku
> contained the following:
>[color=green]
> > $query = "insert into blog values ('$newtext')";[/color]
>
> $query = "insert into blog (blogtext) values ('$newtext')";[/color]


Geoff,

I tried your suggestion. The insert seems to work. But, I still have
the problem of not being able to display the contents of this BLOB
column. Thanks anyway. Perhaps, someone else has a solution.

Bob Kaku
bobkaku@yahoo.com
Geoff Berrow
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Retrieving and Formatting a Blob Object


I noticed that Message-ID:
<e48ec4c8.0403190705.204b1da0@posting.google.com > from Bob Kaku
contained the following:
[color=blue]
>Geoff,
>
>I tried your suggestion. The insert seems to work. But, I still have
>the problem of not being able to display the contents of this BLOB
>column. Thanks anyway. Perhaps, someone else has a solution.[/color]


'Seems' to? Can't you check using phpMyAdmin or something?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Andy Hassall
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Retrieving and Formatting a Blob Object


On 18 Mar 2004 19:47:35 -0800, bobkaku@yahoo.com (Bob Kaku) wrote:
[color=blue]
>I've created a MySQL database to store a large amount of text. Since
>the text data type in MySQL is limited to 255 characters, I added a
>BLOB column.[/color]

Actually, TEXT can store 64k. BLOB isn't for text, it's for binary data
(although the only real difference AFAIK is that using the binary types turns
off case-insensitivity).

VARCHAR can only store 255.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Bob Kaku
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Retrieving and Formatting a Blob Object


Andy Hassall <andy@andyh.co.uk> wrote in message news:<8jkm50deja63lcgh04c3bchbcqnmkqubh4@4ax.com>. ..[color=blue]
> On 18 Mar 2004 19:47:35 -0800, bobkaku@yahoo.com (Bob Kaku) wrote:
>[color=green]
> >I've created a MySQL database to store a large amount of text. Since
> >the text data type in MySQL is limited to 255 characters, I added a
> >BLOB column.[/color]
>
> Actually, TEXT can store 64k. BLOB isn't for text, it's for binary data
> (although the only real difference AFAIK is that using the binary types turns
> off case-insensitivity).
>
> VARCHAR can only store 255.[/color]

Yes, thanks for the answer. I actually found this out myself by doing
a little more research. I now know I can use TEXT, MEDIUMTEXT or
LONGTEXT. But, TEXT seems fine for most uses. I need to examine the
online manual a little deeper before posting a message

Bob Kaku
Closed Thread