By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,369 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,369 IT Pros & Developers. It's quick & easy.

Retrieving and Formatting a Blob Object

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I noticed that Message-ID:
<e4**************************@posting.google.com > from Bob Kaku
contained the following:
$query = "insert into blog values ('$newtext')";


$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/
Jul 17 '05 #2

P: n/a
Geoff Berrow <bl******@ckdog.co.uk> wrote in message news:<55********************************@4ax.com>. ..
I noticed that Message-ID:
<e4**************************@posting.google.com > from Bob Kaku
contained the following:
$query = "insert into blog values ('$newtext')";


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

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
bo*****@yahoo.com
Jul 17 '05 #3

P: n/a
I noticed that Message-ID:
<e4**************************@posting.google.com > from Bob Kaku
contained the following:
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.

'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/
Jul 17 '05 #4

P: n/a
On 18 Mar 2004 19:47:35 -0800, bo*****@yahoo.com (Bob Kaku) wrote:
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.


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 <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #5

P: n/a
Andy Hassall <an**@andyh.co.uk> wrote in message news:<8j********************************@4ax.com>. ..
On 18 Mar 2004 19:47:35 -0800, bo*****@yahoo.com (Bob Kaku) wrote:
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.


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.


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
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.