Forum Moderators: open

Message Too Old, No Replies

Using Mysql with Asp

         

dino2004

2:06 pm on Mar 24, 2006 (gmt 0)

10+ Year Member



Hi guy.

I'm using this script to show my articles in a database mysql.

<%
SQLConn = "Driver={mySQL}; Server=*******; Database=********; Uid=***********; Pwd=********;"

on error resume next
dim objConn,objRecordset
set objConn=server.createObject("adodb.connection")
objConn.open SQLConn

if err.number>0 then
response.write ("errore all'apertura della connessione")
response.end()
end if

dim sql
sql = "SELECT * FROM news ORDER BY data LIMIT 0,30"

set objRecordset=Server.CreateObject("adodb.recordset")
objRecordset.open sql,objConn,1,3

if not objRecordset.eof then
while not objRecordset.eof

response.write "<a href=""articolo.asp?id=" & objRecorset("id") & """ class=""Stile20"">" & objRecordset("titolo") & "</a><br>" & objRecordset("toptesto") & "<br>Pubblicato il: " & objRecordset("data") & "<br><br>"
objRecordset.movenext
wend
else
response.write "no record found"
end if

objRecordset.close: set objRecordset=nothing
objConn.close: set objConn=nothing
%>

In database Mysql there are 1.000 record, but the result is
"no record found"
How can i correct this script?
Thanks

txbakers

3:00 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi and welcome to the webmaster world!

try removing the LIMIT clause and see what happens.

everything else looks good to me. it's a very basic query.

have you run that query in a DB client such as mySQL Front?
also you have a typo here:

objRecorset("id") &
but that would throw an error rather than an EOF.

dino2004

3:40 pm on Mar 24, 2006 (gmt 0)

10+ Year Member



Thanks.
I remove Limit ...

But the result i "No record found"

I've not Mysql front.

What can i do?

txbakers

5:01 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try this.

in your if not EOF section, just do a simple response.write of something to the screen.

my guess is that something in your query isn't correct, but you're not using any where clause so it should return everythin.

have you tried running the query from a command prompt in mySQL?

Demaestro

5:58 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are sure that you have data in that table it is likely the problem is with your database connection and not the SQL.

txbakers

6:32 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought it could be the connection, but he would get "can't connect" errors rather than EOF messages.

Could your connection be pointing to the wrong database? or maybe that user doesn't have read permissions?

dino2004

11:03 am on Mar 25, 2006 (gmt 0)

10+ Year Member



After a lot of experiment (failed) i found this script that allow me to write in db:
<% Dim Conn Dim Rs Set Conn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.Command") Conn.ConnectionString = " server=*******;db=*******;uid=*******;pwd=******;driver=MySQL" Conn.Open Rs.ActiveConnection = Conn Rs.CommandType = 1 Rs.CommandText = "insert into news(titolo) values('testo inserito')" Rs.Execute Conn.Close %>

Can you help me to rewrite the code using this?

Thanks