Connecting Tech Pros Worldwide Help | Site Map

Retrieving and Formatting a Blob Object

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:17 AM
Bob Kaku
Guest
 
Posts: n/a
Default Retrieving and Formatting a Blob Object

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.

  #2  
Old July 17th, 2005, 04:18 AM
Geoff Berrow
Guest
 
Posts: n/a
Default 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/
  #3  
Old July 17th, 2005, 04:18 AM
Bob Kaku
Guest
 
Posts: n/a
Default 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
  #4  
Old July 17th, 2005, 04:18 AM
Geoff Berrow
Guest
 
Posts: n/a
Default 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/
  #5  
Old July 17th, 2005, 04:18 AM
Andy Hassall
Guest
 
Posts: n/a
Default 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>
  #6  
Old July 17th, 2005, 04:19 AM
Bob Kaku
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.