Reply
Accessing MySQL from ASP
Old 09-05-2008, 12:40 AM Accessing MySQL from ASP
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
Does anyone have any sample Classic ASP/VBScript code for accessing a MySQL database?

I have tried a ton of code I found through Google, but nothing seems to work.

Would just like a small piece of code that connects to a MySQL server and database and passes a simple "SELECT title FROM mytable" and displays all the results.
dnavarrojr is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 09-05-2008, 04:48 AM Re: Accessing MySQL from ASP
chrishirst's Avatar
Super Moderator

Posts: 22,277
Location: Blackpool. UK
Trades: 0
Generally it's the same as any other database. Only the driver is different.
Code:
'  SQL server parameters.
const SQLServerName = "ServerName"
const SQLUserName = "User"
const SQLPassword = "pass"
const SQLDatabase = "dbName"  

dim m_sConnString : m_sConnString = "driver={MySQL ODBC 3.51 Driver}"
	m_sConnString = m_sConnString & ";server="
	m_sConnString = m_sConnString & SQLServerName 
	m_sConnString = m_sConnString & ";uid="
	m_sConnString = m_sConnString & SQLUserName 
	m_sConnString = m_sConnString & ";pwd="
	m_sConnString = m_sConnString & SQLPassword
	m_sConnString = m_sConnString & ";database="
	m_sConnString = m_sConnString & SQLDatabase
	m_sConnString = m_sConnString & ";option=16387"

dim m_oConn : set m_oConn = Server.CreateObject("ADODB.Connection")
dim m_oRS : set m_oRS = Server.CreateObject("ADODB.Recordset")

m_oConn.open m_sConnString

dim m_sSQL : m_sSQL = "SELECT fieldlist FROM table"

m_oRS.Open m_sSQL, m_oConn, adOpenStatic, adLockReadOnly, adCmdText

'check recordset and use it if records found
'rest of page code



m_oRS.close
set m_oRS = nothing
m_oConn.close
set m_Conn = nothing
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-05-2008, 04:50 AM Re: Accessing MySQL from ASP
chrishirst's Avatar
Super Moderator

Posts: 22,277
Location: Blackpool. UK
Trades: 0
Quote:
I have tried a ton of code I found through Google, but nothing seems to work.
The ODBC driver is installed on your server / test machine I take it?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-05-2008, 11:54 AM Re: Accessing MySQL from ASP
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
I'll give that a try. I'm hosting with GoDaddy and they don't provide any sample scripts for connecting to MySQL from ASP.
dnavarrojr is offline
Reply With Quote
View Public Profile
 
Old 09-05-2008, 02:24 PM Re: Accessing MySQL from ASP
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,674
Name: John Alexander
Trades: 0
You have to install MyODBC on the server if it's going to work.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 09-05-2008, 02:55 PM Re: Accessing MySQL from ASP
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
Quote:
Originally Posted by Learning Newbie View Post
You have to install MyODBC on the server if it's going to work.
Not my server, so this will be interesting...
dnavarrojr is offline
Reply With Quote
View Public Profile
 
Old 09-05-2008, 03:41 PM Re: Accessing MySQL from ASP
chrishirst's Avatar
Super Moderator

Posts: 22,277
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by dnavarrojr View Post
I'll give that a try. I'm hosting with GoDaddy and they don't provide any sample scripts for connecting to MySQL from ASP.
maybe there's a reason for that.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-05-2008, 03:54 PM Re: Accessing MySQL from ASP
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,674
Name: John Alexander
Trades: 0
Quote:
Originally Posted by dnavarrojr View Post
Not my server, so this will be interesting...
Ahhh. They're asking you to make 2 + 2 = 5?
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 09-06-2008, 02:06 AM Re: Accessing MySQL from ASP
Novice Talker

Posts: 5
Name: Sooper Man
Trades: 0
Ask GoDaddy about the ODBC driver version of mySQL. I had similar problem with my webhosting company. I asked then and after wating for 2 days, finally they gave me driver version of mySQL installed on their servers.
__________________
Read Receipt Get notified when your sent Email Gets Read.
sooperman is offline
Reply With Quote
View Public Profile
 
Old 09-11-2008, 03:27 AM Re: Accessing MySQL from ASP
Junior Talker

Posts: 1
Trades: 0
hi

How can i install mySQL on their servers?
__________________
SEO services india
premarchana is offline
Reply With Quote
View Public Profile
 
Old 09-11-2008, 03:36 AM Re: Accessing MySQL from ASP
chrishirst's Avatar
Super Moderator

Posts: 22,277
Location: Blackpool. UK
Trades: 0
You can't.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-11-2008, 01:44 PM Re: Accessing MySQL from ASP
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
Finally called their support team and they are going to email me the correct connect string shortly.
dnavarrojr is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Accessing MySQL from ASP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.15889 seconds with 13 queries