ถ้าไม่ผ่าน rails จะดู SQL ของ active record ได้อย่างไร

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ผมทดลองเขียน code เพื่อเข้าไป query ข้อมูลใน database ปกติถ้าใช้บน rails ก็จะไปดู log ของ rails ว่ามันสร้าง SQL เป็นอะไร พอทราบหรือเปล่าครับ ว่าตอนที่ไม่ได้ทำงานผ่าน rails เลยไม่รู้จะไปดู SQL ที่ไหนครับ

require 'rubygems'
require 'activerecord'
 
ActiveRecord::Base.establish_connection(
  :adapter => 'mysql',
  :host => 'localhost',
  :username => 'root',
  :password => '',
  :database => 'maintest_development'
)
 
class Maintest < ActiveRecord::Base
  has_many :notes
end
 
class Note < ActiveRecord::Base
    belongs_to :maintest
end
 
a = Maintest.find(:all)
 
a.each do |x|
  print "username = #{x.customername}\n"
end

ติดตั้ง Logger ให้เจ้า activerecord ด้วยคำสั่งนี้

require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT)

Note: ผมมีคำอธิบายวิธีแกะโปรแกรมหาเจ้านี่ ไว้ใน blog ถ้าสนใจก็ไปลองอ่านดูนะ Link

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น