Introduction
This chapter discusses how to write programs that use MySQL. It covers basic application programming interface (API) operations that are fundamental to the programming recipes developed in later chapters. These operations include connecting to the MySQL server, issuing statements, and retrieving the results.
MySQL-based client programs can be written using several languages. The languages covered in this book are Perl , Ruby, PHP, Python, and Java, for which we’ll use the interfaces in the following table. Appendix A indicates where to get the software for each interface.
| Language | Interface |
|---|---|
| Perl | Perl DBI |
| Ruby | Ruby DBI |
| PHP | PEAR DB |
| Python | DB-API |
| Java | JDBC |
MySQL client APIs provide the following capabilities, each of which is covered in a section of this chapter:
- Connecting to the MySQL server, selecting a database, and disconnecting from the server
Every program that uses MySQL must first establish a connection to the server, and most programs also select a default database to use. In addition, well-behaved MySQL programs close the connection to the server when they’re done with it.
- Checking for errors
Many people write MySQL programs that perform no error checking at all. Such programs are difficult to debug when things go wrong. Any database operation can fail and you should know how to find out when that occurs and why. That knowledge enables you to take appropriate action such as terminating the program or informing the user of the problem.
- Executing SQL statements and retrieving ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access