ASP to MYSQL and Basic Database Operations

ASP to MYSQL and Basic Database Operations

We can use two methods to connect to ASP with MySQL. Someone looks like a SQL Server connection. The other is to define DNS.

Before you do both, it is necessary to define MySQL to Windows as ODBC. For this;

Download MyODBC version 3.51 from http://www.mysql.com/downloads/api-myodbc-3.51.html. (The latest version was 3.51 at the time of this writing. If you install a new version, you should use the new version number in the connection process.) I immediately downloaded MyODBC-3.51.06.exe and installed it (732 Kb).

I decided to make a phone book to be a simple example. Let's create a database with phpMyAdmin if it is installed in PHP in our system QL (if I don't install php, you can run MySQL with SQL commands or download MySQLFront from http://www.mysqlfront.de/ and create database with access like interface. Note that you can import the Access files that you previously created with MySQL into MySQL)

CREATE TABLE `telefon_rehberi` (
`id` INT (11) NOT NULL AUTO_INCREMENT,
`adsoyad` VARCHAR (150) NOT NULL,
`is` VARCHAR (20) NOT NULL,
`home` VARCHAR (20) NOT NULL,
`cep` VARCHAR (20) NOT NULL,
`fax` VARCHAR (20) NOT NULL,
PRIMARY KEY (`id`)
);

We have the code to create our table with the above SQL commands.

We currently have a database named ASP, with MyODBC 3.51 installed in our system, and I am assuming that a table named telefon_rehberi has been created in this database.

I'm going to tell you about two types of connection. Let's start with DNS first.

Let's go to Control Panel => Administrative Tools => Data Sources (ODBC) and go to System DNS. Let's select (Add MySQL ODBC 3.51 Driver Araç

As Second Step;

Enter the el Data Source Name kod section in our code

I write the database name that we want to use as a DataBase on MySQL. As the host, continue with localhost, leaving User root and password blank.

When we say ok, we need to see an image above.

 

Now let's go to coding.

Let's create our connection object

Set MySQL_Baglanti = Server.CreateObject ("ADODB.connection")

My database = QL DRIVER = {MySQL ODBC 3.51 Driver}; SERVER = localhost; UID = root; pwd =; dB = asp; "

Let us specify the database we want to reach (we do not use the DNS definition above)

MySQL_Baglanti.Open My Database

We are connecting to the database mentioned above.

If we wanted to connect with the DNS we defined;

MySQL_Baglanti.Open lanti Asp QL

It was enough to use his commands.

After we made our connection, he came to list our data. I'm not telling them now in detail. Our goal here was to connect to MySQL. It is already working the same way as other databases.

<%
Set MySQL_Baglanti = Server.CreateObject (.C ADODB.connection QL)
MySQL_Baglanti.Open lanti Asp QL
Sql = beri select * from telefon_rehberi; ql
set Data = MySQL_Baglanti.execute (Sql)
iF Data.Eof Then
Response.Write Bulun Sorry “No Records Found In Your Phone Directory Resp
else
%>
<%
Do While Not Data.Eof. Loop set up
%>
<%
Data.movenext oven next record
Loop devam keep looping ..
End iF
%>

Name Surname Phone Number Home Phone Mobile Phone Fax

<% = Data ( "Adsoyad")%> <% = Data ( "name")%> <% = Data ( "home")%> <% = Data ( "pocket")%> <% = Data ( " fax ")%>

 

Output of the above codes;

Name Surname Phone Number Home Phone Mobile Phone Fax

Onur Ersin 0 312 385 XX XX 0 312 354 XX XX 0 532 694 XX XX 0 312 354 XX XX

Male Top 0 312 250 XX XX 0312 354 XX XX 0 533 313 XX XX 0 312 354 XX XX

will be in the form of.

If you do not have the chance to use DNS or you do not want to use

MySQL_Baglanti.Open lanti Asp QL

Just replace the line with the following line Sat

My database = "DRIVER = {MySQL ODBC 3.51 Driver}; SERVER = localhost; UID = root; pwd =; db = asp;"
MySQL_Baglanti.Open My Database

Let me briefly mention the addition of data.

Adsoyad, business, home, mobile, fax information by taking the form we have received;

SQL_Ekle = & insert into phone_service (adsoyad, is, home, mobile, fax)

mysql_baglanti.execut A (sql_ekl A)

in the form of MySQL_Baglanti.execute after running the sql i have enough.

<%
adsoyad = Request.Form ( "adsoyad")
is_tel = Request.Form ( "is_tel")
Home = Request.Form ( "home")
mobile = Request.Form ( "pocket")
fax = Request.Form ( "fax")
Set MySQL_Baglanti = Server.CreateObject (.C ADODB.Connection QL)
MySQL_Baglanti.Open lanti Asp QL
sql_ekle = ”INSERT INTO _eski_`telephone_rehberi (` id`, `adsoyad`,` is`, `home`,` cep `,` fax`) VALUES (`, '` & adsoyad & _', 'INT & is_tel & ek', '”& Home & &', '' & cep & & ',' '& fax & &') '
mysql_baglanti.execut A (sql_ekl A)
response.write Ek Data Added to ASP Database response
%>

I hope the samples work for you.