Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. /usr/local/lib/node_modules/mysql/lib/protocol/Parser.js:77
  2. throw err; // Rethrow non-MySQL errors
  3. ^
  4.  
  5. Error: write after end
  6. at writeAfterEnd (_stream_writable.js:133:12)
  7.  
  8. at WriteStream.Writable.write (_stream_writable.js:181:5)
  9.  
  10. at Query._callback (/var/www/html/JS/writeServerDB.js:69:13)
  11.  
  12. at Query.Sequence.end
  13. (/usr/local/lib/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
  14.  
  15. at Query._handleFinalResultPacket (/usr/local/lib/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
  16.  
  17. at Query.EofPacket (/usr/local/lib/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
  18.  
  19. at Protocol._parsePacket (/usr/local/lib/node_modules/mysql/lib/protocol/Protocol.js:280:23)
  20.  
  21. at Parser.write (/usr/local/lib/node_modules/mysql/lib/protocol/Parser.js:73:12)
  22.  
  23. at Protocol.write (/usr/local/lib/node_modules/mysql/lib/protocol/Protocol.js:39:16)
  24.  
  25. at Socket.<anonymous> (/usr/local/lib/node_modules/mysql/lib/Connection.js:96:28)
  26.  
  27. var mysql = require('mysql');
  28. var con = mysql.createConnection({
  29. host: "some numbers",
  30. user: "user",
  31. password: "password",
  32. databse: "database"
  33. });
  34.  
  35. //shows success or failure in the connection
  36. con.connect(function(err){
  37. if(err){
  38. console.log('Error connecting to DB');
  39. return;
  40. }
  41. console.log('Connection Established');
  42. })
  43.  
  44. //begins the read/write connection
  45. var fs = require('fs');
  46. var wstream = fs.createWriteStream('/home/document1');
  47.  
  48. var content = "";
  49.  
  50. //executes the given query and exports it to the console
  51. con.query("SELECT * FROM database.table WHERE ID < 20", function(err, rows, fields){
  52. if(!err){
  53. for(var i = 0; i < rows.length; i++){
  54.  
  55. content = content + "{a lot of data taken from mysql connection} <br/>";
  56. }
  57. //removes the last comma
  58. //content = content.substring(0, content.length - 1);
  59. wstream.write(content);
  60. wstream.on('finish', function(){
  61. console.log('File has been written');
  62. })
  63. console.log(content);
  64. } else{
  65. console.log('Error while performing query');
  66. }
  67. })
  68.  
  69.  
  70. con.end(function(err){
  71. //The connection is terminated gracefully
  72. //Ensures all previously enqueued queries are still
  73. //before sending a COM_QUIT to the mysql server.
  74. })
  75.  
  76. wstream.end();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement