Author |
Message |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Tue Sep 13, 2005 7:42 pm Post subject: BLOB into Database |
 |
|
|
|
I hope someone can help me with this.
Basically, I just want to put the banner of a player into a database for use on a webpage. However, I don't have a clue how to put this BYTE data into a BLOB in the database (in C++ ofcourse).
I tried google and searched alot of sites already, but none can provide me with a real clear answer.
Can someone point me in the right direction? _________________
|
|
Back to top |
|
 |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: Tue Sep 13, 2005 9:01 pm Post subject: |
 |
|
|
|
I can't help you.. but the people at http://daniweb.com/ might be able to answer your question..Then again.. this is about Continuum.
|
|
Back to top |
|
 |
Zim Guest
Offline
|
Posted: Wed Sep 14, 2005 5:32 am Post subject: |
 |
|
|
|
Even thou it's binary treat the banner as a char array/string. to keep it from breaking the query you have to search it for nuls, backslashs, and quotes(acsii 0, 34, 39, and 92). if you find one in the string use the escape sequence(a backslash infront of the character) to let mysql know it's part of the string and not the query itself.
ie. "This'is\a\messed"up'string"
would be "This\'is\\a\\messed\"up\'string"
best way to do this would be use the premade function mysql_real_escape_string().
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 8:08 am Post subject: |
 |
|
|
|
Can you show me some code examples?
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 9:39 am Post subject: |
 |
|
|
|
Currently I have
char* banner = (char*)p->banner;
QLClient.EncodeIntoString(banner, banner); | EncodeIntoString is a method that does the same as mysql_real_escape_string().
This I put into the database. The following output it gives on the attached banner:
H½½½½½½½½½½½HHHH½½½½½½½½HHHmHHHH½½½½HmmHmmHHHHHHHHmmmHHHHHHHHHHHHHHH½½½½HHHH½½½½½½½½H½½½½½½½½½½½ |
However, I don't think this is valid data. I can't get it to ouput to a valid image with PHP:
<?php
$db = mysql_connect("localhost","root","pass") or die("Could not connect to database: " . mysql_error());
mysql_select_db('bots') or die('Could not select database: ' . mysql_error());
$query = "SELECT fbBanner FROM tblonplayer WHERE fnPlayerId = 176";
$result = mysql_query($query);
$data = mysql_result($result,0,"fbBanner");
$img = imagecreatefromstring($data);
$width = imagesx($img);
$height = imagesy($img);
header("Pragma: no-cache");
header("Content-type: image/jpeg");
$out = Imagejpeg($img);
echo $out;
imagedestroy ($img);
?> |
Quote: | Warning: imagecreatefromstring() [function.imagecreatefromstring]: Data is not in a recognized format. in C:\www\image.php on line 9 |
What am I doing wrong?
Banner
DutchAirforce.bmp - 1.15 KB
File downloaded or viewed 21 time(s)
|
|
Back to top |
|
 |
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.

Age:37 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 10:40 am Post subject: |
 |
|
|
|
I'm not sure how it was done for T3G League or player pics (maybe they just used a regular file, I don't know), but maybe you can ask NightHawk or Dustpuppy for more help.
|
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Wed Sep 14, 2005 11:18 am Post subject: |
 |
|
|
|
What I ended up doing was converting it all to a hex string, making it a fixed length 184. Then using PHP etc pull it out of the database, where I took the header of the BMP and re-attached the remaing 96 bytes rebuilt from bottom up, so the banner was in its correct orientation.
What I would have done in my rebuild of the stats plugin (and corresponding PHP) that grabbed all this kind of stuff was to have a dedicated MySQL table for banners with unique ID's and MD5 hashes, then in the player's table, have a column with 'BannerID', so that way if someone had the same banner (ie: players with a null banner) the database wouldn't be filled up with a lot of junked bytes. _________________ Performance is often the art of cheating carefully. - James Gosling
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 11:55 am Post subject: |
 |
|
|
|
Thanks for the tip, Solo, I will certainly ask them
CypherJF, can you copy/paste that code for me? (first part of your reply)
|
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Wed Sep 14, 2005 12:03 pm Post subject: |
 |
|
|
|
I PMed it to you.
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
|
Back to top |
|
 |
Zim Guest
Offline
|
Posted: Wed Sep 14, 2005 4:39 pm Post subject: |
 |
|
|
|
If EncodeIntoString does the same as mysql_real_escape_string() then:
QLClient.EncodeIntoString(banner, banner); |
would overflow banner on the first occurance. when using mysql_real_escape_string() you'd normally make the buffer out twice as big as the input. i dunno about EncodeIntoString but i know it doesn't like you making a pointer to the player struct's banner and then telling it to output into that same place.
here is what you'd want.
char ebanner[200];
QLClient.EncodeIntoString(&p->banner, &ebanner);
but this wouldn't work because EncodeIntoString doesn't know the length of banner and would just run to the first null(\0) and stop. don't use it... use mysql_real_escape_string().
char ebanner[200];
mysql_real_escape_string(&mysql, &ebanner, &p->banner, 96); |
this way mysql_real_escape_string will know that if it hits a \0 before 96 bytes to \0 it and keep going. you may have to typecast p->banner.
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 4:44 pm Post subject: |
 |
|
|
|
thanks alot, I will try that
hm, what is the &mysql for?
nvm, got it
|
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 4:50 pm Post subject: |
 |
|
|
|
WTF
weeeeeee it works
Thanks alot Zim, CypherJF, Dustpuppy, Cerium and Solo Ace for the help .
Now I can continue with the project
|
|
Back to top |
|
 |
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.

Age:37 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
Posted: Wed Sep 14, 2005 5:02 pm Post subject: |
 |
|
|
|
I didn't help at all, but NP.
|
|
Back to top |
|
 |
|