title: Node.js mysql error cannot read property of undefined?
body: <p>I have a program that inserts SMDR data into a database as it comes in.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>var net = require('net'),
      mysql = require('mysql'),
      PORT = 1752,
      HOST = '192.168.10.2',
      pool = mysql.createPool({
          host: 'localhost',
          port: 3307,
          user: 'root',
          password: 'root',
          database: 'mydb'
      });
  
  function connectionListener(conn) {
      console.log('Listening for incoming calls...');
  }
  
  function logCall(phonenumber, operator) {
      pool.getConnection(function(err, connection) {
          if (!err) { // If no error exists 
              var opquery = connection.query('SELECT OperatorID FROM tblOperators WHERE Phone_Login = ' + operator, function(err, rows) {
                  if (err) {
                      console.error(err);
                      connection.release();
                      return;
                  }
                  var query = connection.query('INSERT INTO incoming_calls(phone_number, OperatorID) VALUES("' + 
                  phonenumber + '", "' + rows[0].OperatorID + '") ON DUPLICATE KEY UPDATE OperatorID=OperatorID, date_created=NOW()', function(err, rows) {
                      if (err) {
                          console.error(err);
                      }
                      connection.release();
                  });
              });
          } else {
              console.error(err);
          }
      });
  }
  
  function processdata(data) {
      var phonedata = data.toString().match(/([0-9]?)([0-9]{10})/),
          operdata = data.toString().match(/([*])([0-9]{4})/);
      if (phonedata !== null &amp;&amp; operdata !== null) {
          var phonenumber = phonedata[2], 
              oper = operdata[2];
  
          oper = oper.replace('*', '');
          phonenumber = phonenumber.slice(0,3)+"-"+phonenumber.slice(3,6)+"-"+phonenumber.slice(6);
          logCall(phonenumber, oper);
      }
  }
  logCall('999-999-9999', '1203');
  var conn = net.createConnection(PORT, HOST, connectionListener);
  conn.on('data', processdata);
  conn.setEncoding('utf8');
  </code></pre>
  
  <p>And here is the error that I get, when OperatorID clearly does exist within the table:</p>
  
  <pre><code>c:\xampp\htdocs&gt;node listener
  Listening for incoming calls...
  
  c:\xampp\htdocs\node_modules\mysql\lib\protocol\Parser.js:82
          throw err;
            ^
  TypeError: Cannot read property 'OperatorID' of undefined
      at Query._callback (c:\xampp\htdocs\listener.js:27:48)
      at Query.Sequence.end     (c:\xampp\htdocs\node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
      at Query._handleFinalResultPacket     (c:\xampp\htdocs\node_modules\mysql\lib\protocol\sequences\Query.js:143:8)
      at Query.EofPacket (c:\xampp\htdocs\node_modules\mysql\lib\protocol\sequences\Query.js:127:8)
      at Protocol._parsePacket (c:\xampp\htdocs\node_modules\mysql\lib\protocol\Protocol.js:271:23)
      at Parser.write (c:\xampp\htdocs\node_modules\mysql\lib\protocol\Parser.js:77:12)
      at Protocol.write (c:\xampp\htdocs\node_modules\mysql\lib\protocol\Protocol.js:39:16)
      at Socket.&lt;anonymous&gt; (c:\xampp\htdocs\node_modules\mysql\lib\Connection.js:82:28)
      at Socket.emit (events.js:95:17)
      at Socket.&lt;anonymous&gt; (_stream_readable.js:764:14)
  </code></pre>
  
  <p>Does anyone have any ideas as to why this would happen, I have a production database that uses this, has the same exact information and it works?</p>