Using prepared statements & pointers in Golang
I changed the name of this blog to “a study of bugs”. This makes it easier for me to think of what to write about -- bugs, of course.
In MySQL, you can use a question mark (?) in a prepared statement to stand in for a value.
In the Go code above, dbconn
is a connection to a MySQL server. Line 1 defines a prepared statement. And Line 3 queries the table for a row where the name
column matches the value of variable name
. I assumed the ?
in this query would be interpolated with an actual string. I added quotation marks since they are needed around strings in MySQL CLI.
This fails to return anything. Removing the quotation marks solved the problem. The correct code is on Line 2. ⋯