?
Solved

asp query in mysql

Posted on 2004-05-01
14
Medium Priority
?
682 Views
Last Modified: 2006-11-17

how do i run a query on a mysql server in asp?  i want a dsn-less connection

thanks
0
Comment
Question by:CookieMonster9999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 800 total points
ID: 10969723
0
 
LVL 33

Expert Comment

by:hongjun
ID: 10969729
How do you run?

SELECT Query
=========
Set rs = Conn.Execute("SELECT * from yourtable")

Update / insert/ delete
===============
Conn.Execute "Your update / insert / delete query here"


hongjun
0
 

Author Comment

by:CookieMonster9999
ID: 10969821


Here's what I have from the site:

oConn.Open "Driver={mySQL};" & _
           "Server=db1.database.com;" & _
           "Port=3306;" & _
           "Option=131072;" & _
           "Stmt=;" & _
           "Database=mydb;" & _
           "Uid=myUsername;" & _
           "Pwd=myPassword"

I filled in all my info and get object required
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969947
You need to create a connection object first before opening it - as follows...

Set oConn = Server.CreateObject("ADODB.Connection")
0
 

Author Comment

by:CookieMonster9999
ID: 10969955
thanks
0
 

Author Comment

by:CookieMonster9999
ID: 10969963
i am still having a problem trying to count the number of records in the recordset with this code.  I have


Set oConn = Server.CreateObject("ADODB.Connection")
stroConn = "Driver={mySQL};" & _
           "Server=db1.database.com;" & _
           "Port=3306;" & _
           "Option=131072;" & _
           "Stmt=;" & _
           "Database=mydb;" & _
           "Uid=myUsername;" & _
           "Pwd=myPassword"
oConn.Open stroConn

When i do the following
sqltemp30 = " SELECT * FROM tblImaginary"
Set rstemp30=Server.CreateObject("adodb.RecordSet")
rstemp30.open sqltemp30, stroConn, adopenstatic
howmanyrecs30=rstemp30.recordcount

it always results in -1 no matter how many recs there are in the query

(i've adjusted points to 500 to accomodate answering this additional part)
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969966
Hi, I noticed that you haven't put a value for the 'Server' parameter - this can be your local IP, 192.0.0.1 (for example).
0
 

Author Comment

by:CookieMonster9999
ID: 10969977
i have the queries working, just wondering how to do make record count work.

i've just switched from access to mysql and i'm having to fix all my damn queries :(
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969989
You are using an ADO constant 'adoopenstatis' - in order to utilise that you would need to include the following...

<!-- #include file="adovbs.inc" -->

...which is provided by Microsoft (it enumerates the ADO constants).

Alternatively you can just put the following...

rstemp30.open sqltemp30, stroConn, 3

3 = adOpenKeyset, which is required to return a record count.

0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969999
Apologies :)

3 is adOpenStatic
0
 

Author Comment

by:CookieMonster9999
ID: 10970003
I actually have the file included already.

I tried switching it to 3 and it resulted in:

Microsoft OLE DB Provider for ODBC Drivers error '80040e21'
ODBC driver does not support the requested properties.
 
 
0
 

Author Comment

by:CookieMonster9999
ID: 10970012
Nevermind, it still results in -1.  Here is the query:

sqltemp30 = " SELECT tblGenreMatch.GenreID, tblMusic.SongReviewStatus FROM tblMusic INNER JOIN tblGenreMatch ON tblMusic.SongID = tblGenreMatch.SongID WHERE tblGenreMatch.GenreID= " & genreid & " AND tblMusic.SongReviewStatus='Accepted';"


Set rstemp30=Server.CreateObject("adodb.RecordSet")
rstemp30.open sqltemp30, strMyConn, 3
howmanyrecs30=rstemp30.recordcount
0
 
LVL 6

Assisted Solution

by:Lord_McFly
Lord_McFly earned 1200 total points
ID: 10970016
The following is a snippet from the mySQL website on the subject of using RecordCount...

ADO

When you are coding with the ADO API and MyODBC you need to put attention in some default properties that aren't supported by the MySQL server. For example, using the CursorLocation Property as adUseServer will return for the RecordCount Property a result of -1. To have the right value, you need to set this property to adUseClient, like is showing in the VB code here:
Dim myconn As New ADODB.Connection
Dim myrs As New Recordset
Dim mySQL As String
Dim myrows As Long

myconn.Open "DSN=MyODBCsample"
mySQL = "SELECT * from user"
myrs.Source = mySQL
Set myrs.ActiveConnection = myconn
myrs.CursorLocation = adUseClient
myrs.Open
myrows = myrs.RecordCount

myrs.Close
myconn.Close

Another workaround is to use a SELECT COUNT(*) statement for a similar query to get the correct row count.
0
 

Author Comment

by:CookieMonster9999
ID: 10970139
thanks guys
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question