Storing a String saved as a Variable in a MySQL database?
In a ruby script that sends information to the TWILIO API, I have a string
of characters of characters that their (Twilio's) API outputs. I then have
the console output it so I can save it as a variable and reuse it later:
@client = Twilio::REST:Client.new account_sid, auth_token
call = @client.account.calls.create({:from => 'incoming', :to =>
'outgoing', :url => 'url', :method => 'GET'})
puts call.sid
This part is functional, but now when I rename the variable (//
@incoming_Cid=call.sid //) as to input it into a MySQL database, I bump
into an issue. (The 34 character ID has numbers and letters, so I define
the datatype as VARCHAR).
begin
dbh = DBI.connect("DBI:Mysql:db_name:localhost", "user", "pass")
dbh.do ("INSERT INTO calls (column_name)" #//Select the column to insert
"VALUES (incoming_Cid)") #Insert the 34 character string.
dbh.commit
puts "Customer SID has been recorded"
rescue
puts "A database occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
ensure
dbh.disconnect if dbh
end
Right here at the dbh.do ("INSERT INTO calls " line if I put the
incoming_Cid variable in the VALUES() instead of seeing a 34-char-string,
like CA9321a83241035b4c3d3e7a4f7aa6970d, I literally see 'incoming_Cid'
appear in the database when I execute select * in calls.
How can I resolve this issue?
No comments:
Post a Comment