473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Store BUFR files in MySql

43
Hi guys,

BUFR : WMO format for weather observation data
who knows how to store it info MySql ? please help ~~

thanks a million~

Tanya.
Aug 13 '07 #1
14 2144
pbmods
5,821 Expert 4TB
Heya, Tanya.

You can store BUFR data just like any other file. Simply create a TEXT column in your table, and be sure to mysql_real_escape_string() the contents before putting it in your query.
Aug 13 '07 #2
tanyali
43
Heya, Tanya.

You can store BUFR data just like any other file. Simply create a TEXT column in your table, and be sure to mysql_real_escape_string() the contents before putting it in your query.

thanks for answering first !

this is what I did :
Expand|Select|Wrap|Line Numbers
  1. create table bufr( id int auto_increment primary key, bufr_data text not null ) ; 
  2. insert into bufr values( 1, mysql_real_escakpe_string('/home/...../ob2007080900.gz'));
and it returns :
ERROR 1305 (42000): FUNCTION test.mysql_real_escape_string does not exist

do I need to set something first before use it ?

another thing is , the limitation of text type is 65,535 characters long
and my BUFR files are up to 1120167 bytes,
can it work ?

Tanya
Aug 13 '07 #3
pbmods
5,821 Expert 4TB
Heya, Tanya.

mysql_real_escape_string() is a PHP function, not a MySQL function.

Also, are you trying to store the actual file in the database, or just the path to the file?
Aug 13 '07 #4
tanyali
43
Heya, Tanya.

mysql_real_escape_string() is a PHP function, not a MySQL function.

Also, are you trying to store the actual file in the database, or just the path to the file?
Hi, pbmods
so I need to insert BUFR files through PHP ,

yes, I am trying to store the actual BUFR file in the database,
so do the BUFR files need to be put in the same dir with the PHP page ?


I still do not quite understand how to use this function to insert BUFR into db...

Tanya
Aug 15 '07 #5
tanyali
43
Heya, Tanya.

mysql_real_escape_string() is a PHP function, not a MySQL function.

Also, are you trying to store the actual file in the database, or just the path to the file?

and this is what I used in PHP:
Expand|Select|Wrap|Line Numbers
  1. $query = sprintf("INSERT INTO  (`id`, `name`, `number`,`date`,`bufr_data`) VALUES (%d, '%s', %d, %d, '%s')", 1 , ob2007080900.gz, 0, 20070809,
  2. mysql_real_escape_string(ob2007080900.gz(the name of a BUFR file put in the same dir with this PHP page), $link) );
  3.  
  4.         mysql_query($query, $link);
  5.  
  6.         if (mysql_affected_rows($link) > 0)
  7.             echo "Product inserted\n";
  8.         else
  9.             echo "failure";
PS: I am sure no problem with the db connection.

but it returned "failure"......
Aug 15 '07 #6
dafodil
392 256MB
Please display the complete error message.

Please also check your code below, I think it got complicated because you combined different methods as one statement.
Expand|Select|Wrap|Line Numbers
  1. $query = sprintf("INSERT INTO (`id`, `name`, `number`,`date`,`bufr_data`) VALUES (%d, '%s', %d, %d, '%s')", 1 , ob2007080900.gz, 0, 20070809,
  2. mysql_real_escape_string(ob2007080900.gz(the name of a BUFR file put in the same dir with this PHP page), $link) );
  3.  
Aug 15 '07 #7
tanyali
43
Please display the complete error message.

Please also check your code below, I think it got complicated because you combined different methods as one statement.
Expand|Select|Wrap|Line Numbers
  1. $query = sprintf("INSERT INTO (`id`, `name`, `number`,`date`,`bufr_data`) VALUES (%d, '%s', %d, %d, '%s')", 1 , ob2007080900.gz, 0, 20070809,
  2. mysql_real_escape_string(ob2007080900.gz(the name of a BUFR file put in the same dir with this PHP page), $link) );
  3.  
stupid mistake...
Expand|Select|Wrap|Line Numbers
  1. $query = sprintf("INSERT INTO BUFR (`id`, `name`, `number`,`date`,`bufr_data`) VALUES (%d, '%s', %d, %d, '%s')", 1 , ob2007080900.gz, 0, 20070809,
  2. mysql_real_escape_string(ob2007080900.gz(the name of a BUFR file put in the same dir with this PHP page), $link) );
  3.  
  4. mysql_query($query, $link);
  5.  
  6. if (mysql_affected_rows($link) > 0)
  7. echo "Product inserted\n";
  8. else
  9. echo "failure";
forgot the name of the table !!!

but it seems that what has been inserted into the db is the name( only the string "ob2007080900.gz") instead of the actual BUFR file named ob2007080900.gz !

...

Tanya
Aug 15 '07 #8
pbmods
5,821 Expert 4TB
Heya, Tanya.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Instead of using the file name, you need to actually load the file's contents into a string and save that instead.

Expand|Select|Wrap|Line Numbers
  1. $data = mysql_real_escape_string(file_get_contents('/path/to/file.ext'));
  2.  
  3. $sql = "
  4. INSERT
  5.     INTO
  6.         `Table`
  7.     .
  8.     .
  9.     .
  10.     VALUES
  11.         (
  12.             '{$data}'
  13.     .
  14.     .
  15.     .
  16.  
Aug 15 '07 #9
tanyali
43
Hi pbmods,

thanks, it did work for files with limitation of 65535 byte !
but most of my files are much more than that up to 1120167 byte.

any other way to store them ?

thanks a million !!
Tanya.
Aug 15 '07 #10
pbmods
5,821 Expert 4TB
Heya, Tanya.

Because you are loading the file into memory to store it, you also need to increase PHP's memory limit.

Use the following statement:
Expand|Select|Wrap|Line Numbers
  1. ini_set('memory_limit', '1024M');
  2.  
Aug 15 '07 #11
tanyali
43
Hi pbmods,

I meant 65535 characters is the limitation of the type "text" in MySql.
Aug 15 '07 #12
pbmods
5,821 Expert 4TB
Heya, Tanya.

Hi pbmods,

I meant 65535 characters is the limitation of the type "text" in MySql.
Good thing I'm on the ball with these things :P

Have a look at this document, towards the bottom. Instead of a TEXT, you'll probably want a LONGTEXT or LONGBLOB, depending on whether you are storing an ASCII or a Binary file, respectively.
Aug 15 '07 #13
tanyali
43
Heya, Tanya.



Good thing I'm on the ball with these things :P

Have a look at this document, towards the bottom. Instead of a TEXT, you'll probably want a LONGTEXT or LONGBLOB, depending on whether you are storing an ASCII or a Binary file, respectively.
pbmods,
got it, use LONGTEXT!
How can I express my thanks to you.... I love you so much !!

Regards,
Tanya
Aug 16 '07 #14
pbmods
5,821 Expert 4TB
Heya, Tanya.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 16 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cover | last post by:
The question is, we have two options to store images, either in a Database (MySQL, Postgres, ...) like blob data, or in the hard disk the file and the path in database. Which option is better?...
0
by: Ivan Horvath | last post by:
Dear All, i would like to store binary file contents to a mysql database in a mediumblob fields. i've got problem when there is a simple quote, double quot, backslash or NUL character in the...
0
by: Donald Tyler | last post by:
Yes it can. But you should understand the three distinct levels of that situation. You need the following: Database Web Server Server-Side Scripting Language I would suggest using AMP...
12
by: jacob nikom | last post by:
Hi, I would like to store XML files in MySQL. What is the best solution: 1. Convert it to string and store it as CLOB/text 2. Serialize it and store as byte array 3. Flatten it out and create...
3
by: guy | last post by:
Hi, How do I store pictures in mySQL? What is the data type for this field? TIA
5
by: lawrence k | last post by:
I'm a little weak on my basic I/O. Help me out please. Is it right to say that I can just open any file with file(), get it as a string, and then store in a MySql database, in, say, a MediumText...
7
by: mukeshpatil | last post by:
How to get data from .CSV file using php & store it into Mysql database I want to read data from two different .CSV files using php & How to store it into Mysql Database tables Please help me...
1
by: akashkhasgiwala | last post by:
i am developing i web application in which every user will have an Xml File containing mostly text and date/time stamps this application will use MySql for storing data so pl tell me if i can STORE...
4
Dormilich
by: Dormilich | last post by:
Hi, short: I want to figure out which construct is best suited to store nested values in a template class. background: For my website, I have a template class, that provides my output class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.