![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | MySQL query This simple script connects to a MySQL database and displays the results of a query. So far it will only display the first record from the query. If the query returns more than one record only the first record is displayed. I'd like to save the entire results of the query to a file as well as diplay them on screen. Is this possible? I quoted out the If.. Else block because the script would hang. DIM objConn, strConnection, objRS, strQuery Set objConn = CreateObject("ADODB.Connection") strConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=192.168.0.1; PORT=3306;" &_ "DATABASE=mydb; USER=user; PASSWORD=password; OPTION=3;" objConn.open strConnection set objRS = CreateObject("ADODB.RecordSet") set objRS.ActiveConnection = objConn strQuery = "select login,password from users where companyid=105" objRS.Open strQuery 'If objRS.EOF Then 'Wscript.Echo "Record cannot be found." 'Else 'Do until objRS.EOF wscript.echo objRS("login") & " " & objRS("password") 'loop 'End if objRS.close Set objRS = Nothing objConn.close Set objConn = Nothing |
My System Specs![]() |
| | #2 (permalink) |
| | Re: MySQL query James schrieb: Quote: > This simple script connects to a MySQL database and displays the results > of a query. So far it will only display the first record from the > query. If the query returns more than one record only the first record > is displayed. I'd like to save the entire results of the query to a > file as well as diplay them on screen. Is this possible? I quoted out > the If.. Else block because the script would hang. > > DIM objConn, strConnection, objRS, strQuery > Set objConn = CreateObject("ADODB.Connection") > > strConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=192.168.0.1; > PORT=3306;" &_ > "DATABASE=mydb; USER=user; PASSWORD=password; OPTION=3;" > objConn.open strConnection > set objRS = CreateObject("ADODB.RecordSet") > set objRS.ActiveConnection = objConn > > strQuery = "select login,password from users where companyid=105" > > objRS.Open strQuery > 'If objRS.EOF Then > 'Wscript.Echo "Record cannot be found." > 'Else > 'Do until objRS.EOF > wscript.echo objRS("login") & " " & objRS("password") objRS.MoveNext Quote: > 'loop > 'End if > > objRS.close > Set objRS = Nothing > objConn.close > Set objConn = Nothing |
My System Specs![]() |
| | #3 (permalink) |
| | Re: MySQL query "James" <jwanders@xxxxxx> wrote in message news:53Klm.185171$vp.35604@xxxxxx Quote: > This simple script connects to a MySQL database and displays the results > of a query. So far it will only display the first record from the query. > If the query returns more than one record only the first record is > displayed. I'd like to save the entire results of the query to a file as > well as diplay them on screen. Is this possible? I quoted out the If.. > Else block because the script would hang. > > DIM objConn, strConnection, objRS, strQuery > Set objConn = CreateObject("ADODB.Connection") > > strConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=192.168.0.1; > PORT=3306;" &_ > "DATABASE=mydb; USER=user; PASSWORD=password; OPTION=3;" > objConn.open strConnection > set objRS = CreateObject("ADODB.RecordSet") > set objRS.ActiveConnection = objConn > > strQuery = "select login,password from users where companyid=105" > > objRS.Open strQuery > 'If objRS.EOF Then > 'Wscript.Echo "Record cannot be found." > 'Else > 'Do until objRS.EOF > wscript.echo objRS("login") & " " & objRS("password") > 'loop > 'End if > > objRS.close > Set objRS = Nothing > objConn.close > Set objConn = Nothing forever. You need to add a MoveNext statement in the loop. For example: ======= If objRS.EOF Then Wscript.Echo "Record cannot be found." Else Do until objRS.EOF wscript.echo objRS("login") & " " & objRS("password") objRS.MoveNext loop End if ========= Even if you expect only one record in the recordset, the EOF condition will never result if you don't move to the next record. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| execute mysql query using vbscript | VB Script | |||
| mySQL on Vista x64 | Software | |||
| i cannot connect to my odcb driver, mysql .. need query string | PowerShell | |||
| Vista doesnt like MySQL | Vista General | |||