mysql - inserting/reading blob data from php -


.

After

I have been using the following scripts to test and then reading the Blob data

the entry script : Include

  ('session.php'); $ Provider = $ _ POST ['provider_id']; $ Trd_period = $ _ POST ['trading_period_month']; $ Pdf_statement = stream_get_contents (fopen ($ _files ['pdf_statement'] ['tmp_name'], 'rb')); $ Pdf_statement_clean = addslashes ($ pdf_statement); '.. $ Pdf_statement_clean $ insert = "Update rd_provider_statement set pdf_statement =" ", creation_user_id = 'SCO' where provider_id = '" $ provider .. "'And trading_period_month =' $ trd_period .. "'"; Mysql_query ($ insert); Mysql_query ("COMMIT"); Echo mysql_error ();   

Download the script: Include

  ('session.php'); // post variable $ TP_Month = $ _ POST ["trading_period_month"]; $ Provider = $ _ POST ["provider_id"]; $ TP_format = substr ($ TP_Month, 0, 7); // Download statement $ sql_qry = "Select * rd_provider_statement from where provider = '" $ provider .. "'And trading_period_month ='" $ TP_Month .. "'"; $ Sql_err_no = sql_select ($ sql_qry, $ sql_res, $ sql_row_count, $ sql_err, $ sql_uerr); $ Line = mysql_fetch_assoc ($ sql_res); $ Bytes = Strip Soul ($ line ['pdf_statement']); Header ("content-type: application / pdf"); Header ('content-effect: attachment; file name =' '. $ Provider.'statement' $ TP_format. '.' ''); Print $ bytes;   

However, when the file is downloaded it can not open on the basis that it is not a supported format. I use the base of the script on a page database to download bob data from the database however here the entry is done by a mysql process and not php. I think this is my entry script which is causing the problem. Try

mysql_real_escape_string () instead of Addslashes () . This can fix the problem for you.

For debugging, you can calculate the string md5 () before inserting it into DB and then after retrieving it, I bet you get different hashes , Which means that you are not inserting it properly and when you join DB your binary data becomes corrupted.

Side notes:

  • Do not use inserts like this, use compulsory -
  • Check and prevent errors, only resonate them Do not (I hope you are doing this in your production code)

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -