programmingsite : code , tutorials and scripts
Navigation

home


ASP
ASP.net
C
C++
C#
PHP
Java
JavaScript
Powershell
VB.net

Visual Basic


Resources
code
tutorials
training

Ads
Products

 

 

Connect to a MySQL database




Connect to a MySQL database

In this example we will show you how to connect to a MySQL database .


Create a database like this.

CREATE DATABASE example;
USE example;

CREATE TABLE example(url VARCHAR(40) , description TEXT);

INSERT INTO example VALUES('http://www.google.com' , ' The best search engine');
INSERT INTO example VALUES('http://www.beginnersphp.co.uk' , 'top notch php site');
INSERT INTO example VALUES('http://www.myscripting.com','Scripting resources galore here');

This is a simple example which will display links on your page , now lets move on to the script

In the example below remember and change the uid and pwd to your own username and password .



<%
'declare some constants that are used in the script
Dim adOpenForwardOnly , adLockReadOnly , adCmdTable
adOpenForwardOnly = 0
adLockReadOnly =1
adCmdTable =2
'variable declaration in here
Dim objConn , objRS
'create our objects
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
'connect to the MySQL example database
objConn.Open "driver={MySQL};server=localhost;uid=username;pwd=password;database=example"
'open the example table
objRS.Open "example" , objConn , adOpenForwardOnly , adLockReadOnly , adCmdTable
'display all data in the table
While Not objRS.EOF
Response.Write objRS.Fields("URL") & "&nbsp"
Response.Write objRS.Fields("description") & "&nbsp"
Response.Write "<p>"
objRS.MoveNext
Wend
'close recordset
objRS.Close
'destroy all objects
Set objRS = Nothing
Set onjConn = Nothing
%>



Products
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals
Asp Studio 2005
Xtra PHP
Online PHP Script Encoder
Comparison

Links
Make money selling software
Uk shopping
UK price comparison
US price comparison
free articles
free stuff
Gambling resources
Software directory
XBox cheats and more
Sexy free wallpapers
Hosting resources
Nintendo Wii info
Beginners PHP
Health and fitness
Domain names
Dating site
Nintendo DS resources
Dropshippers
Maxi directory
Perfume and fragrances
PC shopping, tips and info
Magazine superstore

Ads