Delphi Connection MySQL

Source: Internet
Author: User
Tags dsn odbc

Delphi Connection MySQL really trouble, research a day, from the Internet to find countless articles, downloaded countless plugins are not resolved. Finally back to basics, honestly with ADO to connect, found not very smooth, but eventually connected successfully. How much a bit of experience: ADO each component role and contact must be clear, otherwise set up easily confusing. Summarize the key points for connecting MySQL5.1 with ADO:

1, need to download the MySQL ODBC support, I use the official website Mysql-connector-odbc-5.1.7-win32.msi (This generally no problem, download and install it)

2, through the ODBC management to establish the System DSN (this is also simple, is to choose MySQL ODBC, set the server, user name, password)

3, familiar with ADO control know its role and mutual connection. Difficulties

The Tadoconnection function is to connect to the default database Defaultdatabas (MySQL) by setting the ConnectionString connection string (for example: Server localhost, user name root, password 123456).

Tadoquarry function is to execute the query statement and Save the query results , you need to set up SQL (such as select * from user;), the SQL statement here can only be one. The component is closely linked to tadoconnection, and the connection property should be set to an instance of tadoconnection (such as Conmysql).

This has the database connection, has the query operation, the remaining task is to display the result. There are two components to support:

Tdatasource as the name implies: a data source is a bridge between data display and query results, and its DataSet property is set to an instance of Tadoquarry (Qrymysql)

Tdbgrid is the data component that displays the results, with the DataSource property set to the Tdatasource instance (such as Dsmysql)

4. Activate the connection to take effect, Tadoconnection's connected is set to true, and Tadoquarry's active setting is true.

In real-world applications, you do not have to establish a System DSN, you can create a connection dynamically by simply installing ODBC.


Source: <delphixe Connect mysql5.1-delphi7456-Blog Park >  
procedureTForm1.Button1Click(Sender:TObject);
begin
Try
ADOConnection1.ConnectionString:=(' Driver={mysql ODBC 3.51 DRIVER}; '+
' server=localhost; '+
' database=wm; '+
' user=root; '+
' PASSWORD=MCNCC; '+
' option=3; ');
ADOConnection1.Close;
ADOConnection1.Open;
except
Application.MessageBox(' could not connect to the database server. Contact your administrator ',' Tips ',mb_iconinformation);
End;
ADOQuery1.Active:=true;
End;



 

From for notes (Wiz)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.