Skip to content

Instantly share code, notes, and snippets.

@aedorado
Created August 20, 2016 11:12
Show Gist options
  • Save aedorado/4b0651c6a463bcd9b11cdd9a570725e2 to your computer and use it in GitHub Desktop.
Save aedorado/4b0651c6a463bcd9b11cdd9a570725e2 to your computer and use it in GitHub Desktop.
Generate bindParam statements for given sql query
import sys
s = "SELECT * FROM course_strucure WHERE program_id = :program_id AND year_of_joining = :year_of_joining AND sem_code_of_joining = :sem_code_of_joining"
s = sys.argv[1]
print ( "$sql = \"" + s + "\";" )
s = s.split()
s = [x for x in s if x[0]==':']
print ( "$stmt = $conn->prepare($sql);" )
for x in s:
print ( "$stmt->bindParam('" + x + "', $" + x[1:] + ");")
print ( "$stmt->execute();" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment