library(RMySQL)
sqlQuery <- function (query) {
# creating DB connection object with RMysql package
DB <- dbConnect(MySQL(), user="user", password="password",
dbname="databaseName", host="host")
# close db connection after function call exits
on.exit(dbDisconnect(DB))
# send Query to obtain result set
rs <- dbSendQuery(DB, query)
# get elements from result sets and convert to dataframe
result <- fetch(rs, -1)
# return the dataframe
return(result)
}
1条答案
按热度按时间mf98qq941#
您可以创建一个函数来检索查询。
然后就是:
希望有帮助