title: Django mysql prepared statements
body: <p>Hello i trying to use mysql prepared statements in django.</p>
  
  <p>I made a following class:</p>
  
  <pre><code>class PreparedStatement(object):
  
      def __init__(self,name,query):
          self.name = name
          self.query = query
          self.vars = []
          self.prepare()
  
      def setVar(self,name,var):
          name = "@%s" % name
          if name not in self.vars:
              self.vars.append(name)
          SQL = "SET %s = " % (name)
          self.__executeQuery(SQL+" %s;",var)
  
      def prepare(self):
          SQL = "PREPARE %s FROM " % self.name
          self.__executeQuery(SQL + " %s ;", self.query)
  
      def execute(self):
          SQL = "EXECUTE %s " % self.name
  
          if len(self.vars):
              params = ""
              for var in self.vars:
              params += var + ", "
              params = params[:-2]
              SQL += "USING %s " % params
          result =  self.__executeQuery(SQL)
          self.vars = []
          return result
  
      def __executeQuery(self,query,*args):
          cursor = connection.cursor()
          if args:
              cursor.execute(query,args)
          else:
              cursor.execute(query)
          return cursor
  </code></pre>
  
  <p>and i use it like this:</p>
  
  <pre><code>getDiscountsById = PreparedStatement("getDiscountsById","""SELECT * FROM table 
  WHERE id = ? LIMIT 1""")
  getDiscountsById.setVar("id",5)
  result = getDiscountsById.execute()
  </code></pre>
  
  <p>It is working fine for first loaded page , but after changing url or reloading page MySQL returns prepared statement not found error.</p>
  
  <p>Where could be the problem? Is there any solution ?</p>
  
  <p>Thanks for responses and sorry for my english :D</p>