MySQL Database Connection with ASP or VBScript using QTP tool

To query a MySQL database using Classic ASP you will need to use one of  the MySQL ODBC drivers installed on our system:
  • MySQL ODBC 5.3 Unicode Driver
  • MySQL ODBC 5.3 ANSI Driver

Suppose if your not installed odbc mysql driver means, first need to install. To install mysql odbc driver please follow the given link
http://sql-articles.com/articles/dba/creating-linked-server-to-mysql-from-sql-server/

 Example connection string using Classic ASP or VBScript(QTP tool) to call on a MySQL database:
Dim obj’‘ create a connection object
Set conn = createobject(“ADODB.connection”)’‘ create recordset object
Set MyRecordset = CreateObject(“ADODB.Recordset”)

‘‘ Connection string to connect MySQL database using ODBC 3.51 driver
‘Srvname = “driver={MySQL ODBC 3.51 Driver};server=192.168.10.18;port = 3306 ;User Id=root;Password=qadex_16Mar15; database=qadex_16Mar15”
‘Srvname = “driver={MySQL ODBC 5.3.4 Driver};server=192.168.10.18;port = 3306 ;User Id=root;Password=password; database=qadex_16Mar15” ‘Statndard Driver
Srvname = “DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=192.168.10.18; DATABASE=qadex_16Mar15;USER=root;PASSWORD=password;OPTION=3;” ‘Unicode Driver
‘Srvname = “DRIVER={MySQL ODBC 5.3 ANSI Driver};SERVER=192.168.10.18; DATABASE=qadex_16Mar15;USER=root;PASSWORD=password;OPTION=3;” ‘ANSI Driver

‘‘ established connection with server using provided data in to query string.
conn.open Srvname

‘‘ A database operation query which needs to be performed.
‘SQL=”SELECT * FROM members where title=SGPP”
‘SQL=”insert into members(title,content,manufacturer,supplier,file_name)values(‘SGPP Correct’,’hi hello’,’Aaron’,’Sumner’,’testfile’)”
val=”select * from members order by id desc limit 1″

‘val=”select * from members where title=SGPP”
SQL=val’‘ Execute database query using already established connection and store result in to my record set.
MyRecordset.Open SQL,conn’‘ Store value of any fieldm
obj = MyRecordset.fields.item(“title”)

‘‘ message box to show that value
msgbox obj

‘‘ close my recordset
MyRecordset.Close

‘‘Close db connection
conn.Close

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s