Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: MySQL Blob / DBI quote ?

by gmax (Abbot)
on Dec 19, 2003 at 22:14 UTC ( #315932=note: print w/replies, xml ) Need Help??


in reply to MySQL Blob / DBI quote ?

That didn't work.

That isn't the kind of remark that will help us to solve your problem. Perhaps you should read (and meditate upon) Before asking a database related question .... The most important piece of information from that node is about creating a test case for submission. Please try it.

BTW, I remember now that I gave you the same advice for a different problem, but you don't seem to be listening.

As for your case, you say that you are quoting $string, but you failed to mention what $string is. Is it your query? Your shopping list? Your cat's favorite food? Or a variable containing your text? Please give us more details. A few lines od code replicating your problem would be helpful.

In addition to hardburn's advice on using placeholders, you can also have a look at a practical example where placeholders are used successfully with BLOB fields ( Handling huge BLOB fields with DBI and MySQL).

 _  _ _  _  
(_|| | |(_|><
 _|   

Replies are listed 'Best First'.
Re: Re: MySQL Blob / DBI quote ?
by Anonymous Monk on Dec 20, 2003 at 21:28 UTC
    Hey - I further read more on the quote option and that was totally the wrong direction to fix my problem. I'm trying to add memo's to a database, some memos are way more the 255 characters so I changed the "memo_text" field into a blob columntype instead of "varchar(255) not null." Heres my code:
    $time = time; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $mon++; $year += 1900; $memo = "Original Message\n------------\n$INPUT{'memo'}"; $memo_final = $memo . "\n\nCreated by: $username\nDate Created: $year- +$mon-$mday\n\n"; use DBI; my $dbh_m = DBI->connect('DBI:mysql:MEMO') or print "Couldn't con +nect to database: " . DBI->errstr; $sql_m = " INSERT INTO memo VALUES ( '?', '$year-$mon-$mday', '$INPUT{'user'}', '$INPUT{'ref'}', '$INPUT{'username'}', 'notread', '$memo_final' ) "; $sth_m = $dbh_m->prepare($sql_m) or print "preparing: ",$dbh_m->errst +r; $sth_m->execute or print "executing: ", $dbh_m->errstr; $sth_m->finish; $dbh_m->disconnect; &header; print <<EOF; <B>Memo to $INPUT{'user'} successfully added.</b> <br> EOF &footer;


    Now, previously when the column type was "varchar(255) not null" , this insert code worked fine and all memos were added successfully.

    But when I altered the table to make it a blob column type this insert code returns a error giving me:

    executing: You have an error in your SQL syntax near 've been trying t +o figure out how come this doesn't work for me. I have a insert ' at +line 12


    Part of that error message is due to the fact that the memo I tried insterting included the sentence 'I've been trying to figure out how come this doesn't work for me. I have a insert '

    Thank you,
    Anthony
      Now, previously when the column type was "varchar(255) not null" , this insert code worked fine and all memos were added successfully.

      I don't think so. It could not possily work with any value of $memo. For example, you are preparing a query with one placeholder and then you are executing without parameters. And your placeholder is quoted, so it could not work.

      Further advice: use strict.

      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315932]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-12-03 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?