在rails中执行sql语句

        sql = ActiveRecord::Base.connection()
        sql.insert "INSERT INTO #{UC_DBTABLEPRE}members SET username='#{@user.uname}', password='#{password}', email='#{@user.email}', regip='1.1.1.1', salt='#{salt}'"
        last_user_id = sql.select_value("SELECT uid FROM #{UC_DBTABLEPRE}members WHERE email='#{@user.email}'")
        unless last_user_id.nil?
          sql.insert "INSERT INTO #{UC_DBTABLEPRE}memberfields SET uid='#{last_user_id.to_s}', blacklist=' '"
        end

 其他的api还有:

    *  add_limit!
    * add_limit_offset!
    * add_lock!
    * begin_db_transaction
    * commit_db_transaction
    * default_sequence_name
    * delete
    * delete_sql
    * empty_insert_statement
    * execute
    * insert
    * insert_fixture
    * insert_sql
    * reset_sequence!
    * rollback_db_transaction
    * sanitize_limit
    * select
    * select_all
    * select_one
    * select_rows
    * select_value
    * select_values
    * transaction
    * update
    * update_sql

 

请查rails文档

你可能感兴趣的:(rails)