Working with Visual Studio, Windows 7 and mysql.h library.
What I want to do is send a MySQL query like this:
mysql_query(conn, "SELECT pass FROM users WHERE name='Leo Tolstoy'");
The only thing I can’t get working is sending a query where the name would be not a constant as it’s shown above, but a variable taken from a text field or anything else. So how should I work with a variable instead of a constant?
Hope I made my question clear.
Use a prepared statement, which lets you parameterize values, similar to how functions let you parameterize variables in statement blocks. If using MySQL Connector/C++:
Create classes to handle database access and wrap that in a method, and the rest of the application doesn’t even need to know that a database is being used.
If you really want to use the old C API for some reason:
As you see, Connector/C++ is simpler. It’s also less error prone; I probably made more mistakes using the C API than Connector/C++.
See also: