1
DB = Mysql.real_connect("localhost", "admin", "pass", "main")
number = 12345 #This number exists in table
#Create Date Entry
booking_exists = DB.query("SELECT count(*) FROM booking WHERE number='#{number}';").fetch_row

number = 12345 #This number does not exist in table
booking_exists = DB.query("SELECT count(*) FROM booking WHERE number='#{number}';").fetch_row
if booking_exists[0][0][0] > 0
  puts "Skipping Existing Booking #{number}"
end

所以它计算存在的变量数量。第一个返回 1。第二个应该返回 0,但它也返回 1,除非我再次运行查询。我似乎找不到寻找这个的原因。我应该做某种刷新查询吗?

谢谢

4

0 回答 0