3

following code is written by R language function : save html file into database

html_binary <- paste(readBin("EventChart3.html", what="raw", n=1e6), 
collapse='')
sql<-paste0("INSERT INTO test (`att`) VALUES ('",html_binary,"')")
dbSendQuery(connect,sql)

following code is written by PHP language function : show the html file

$sql=sprintf("select * from test where id=37"); 
$result=mysql_query($sql);      
$row=mysql_fetch_assoc($result)  ;
print $row['id']."</br>";
header("content-type:text/html");     
echo $row['att'];

table only have two attribute 1. id : autoincrement ,int 2. att : save binary file , BLOB

my php show a lot of binary code, I don't know how to solve it. please give me help,thanks all

chun-hsu
  • 31
  • 3
  • Have you tried to search for decoding binary like: https://stackoverflow.com/questions/6382738/convert-string-to-binary-then-back-again-using-php ? – Rasclatt Jul 09 '18 at 03:46
  • I did,but i don't need to convert the string.I just want to show the html file,not its code – chun-hsu Jul 09 '18 at 05:14
  • What do you mean, you want to show the html file, not the code? Aren't you trying to get the html string you stored in binary back into the browser? I am a bit confused about what you are expecting to see. – Rasclatt Jul 09 '18 at 15:09
  • My target is save the whole html file into DB,and show it using PHP. but I don't know how to fix it......maybe I mistake your mean – chun-hsu Jul 10 '18 at 01:09
  • I try your suggest . PHP shows number too large – chun-hsu Jul 10 '18 at 08:51
  • Why do you have to save it as binary? Why can't you store it in a `LONGTEXT` as a string? Does `r` not have that ability? – Rasclatt Jul 10 '18 at 15:51
  • thank you . now I use LONGTEXT type to save, but still have trouble...... – chun-hsu Jul 11 '18 at 00:46
  • But you don’t want to save binary to it, you want to save the string data to it, basically the contents of the html – Rasclatt Jul 11 '18 at 01:00

0 Answers0