Q&A
Q: How are my queries executed?
A:
The SQL statements that you embed in your program are passed to the
driver. This driver contains all the database-specific functions. The driver
calls the function that runs your query against the database. The result of
this function is your resultset.
Q: Can I create databases using an interface?
A:
You can do pretty much anything that you could do in the MySQL monitor. If
you have the correct permissions, you can use CREATE, DROP, ORGANIZE,
INSERT, DELETE, and UPDATE records and databases. You have the power
to automate administrator tasks or manipulate the data through a program
you can create.
Q: What interfaces are available for MySQL?
A:
MySQL has many interfaces and drivers. Some were created by TcX and
some are third-party creations. There are interfaces for Perl (DBD/DBI),
ODBC (MyODBC), Java (JDBC), C/C++, Python, and PHP. Because
MySQL is ODBC-compliant, you can use tools like VBScript, Visual Basic,
Access, Crystal Reports or any other tool that can use an ODBC data
source.
Exercises
- List the advantages and disadvantages to using an interface as opposed to the
MySQL Monitor program. - What are the basic requirements for a database connection?
Day 13: How to Use MyODBC
Overview
The MyODBC interface is just one of the ways you can interact with your MySQL data on the Windows
platform. Microsoft has created and embraced this technology and has made it an integral part of many of
their applications.
Microsoft’s Open Database Connectivity (ODBC) is a standard that allows a user to access any
database using the same series of commands. It provides a layer of abstraction between the program
and the database. Each database has its own ODBC driver that adheres to Microsoft’s ODBC standard.
This driver acts as the layer of abstraction. You can think of the ODBC driver as a translator. In your
programs, you will issue a command that will be interpreted by the driver. This driver will forward this
interpreted command to the database. The database will then send the result set or message back to
the driver, which, in turn, will send it back to the application. This architecture allows the programmer to
use the same code to interact with a database, regardless of what database to which it is talking. This
works as long as the programmer sticks to the ANSI SQL standard when issuing commands. If the
programmer uses database-specific commands, the ability to reuse is nullified.
If you create programs for a Windows platform (this includes Active Server Pages), more than likely you
will use ODBC to talk to your database. ODBC is easy to use and follows the same steps you learned
about yesterday.
In the examples and lessons today you will use ODBC to talk to a MySQL database. To do this, you will
create an Active Server Page (ASP) using VBScript. Today you will also learn
How to get and install the MyODBC driver
How to set up a Data Source Name (DSN)
How to connect to a MySQL using ADO (ActiveX Data Objects)
Create an Active Server Page to access a MySQL database
Where Do I Get the Driver?
To begin using ODBC in your applications, you must first have the ODBC driver for your database. Microsoft
automatically installs several of its drivers. Some databases install the ODBC driver during the initial
application installation as well. If you perform the following steps, you can see what drivers are installed on
your computer right now.