Results 1 to 8 of 8

Thread: mySQL: How to implement/use?

  1. #1

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    mySQL: How to implement/use?

    I've a hosted domain, get SQL support.
    But how do I use it? I was just given my username and password
    for that SQL database.
    Wut should I use and do?

    Thx!
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  2. #2
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Well, just open Query Analyzer if you have any queries to run. If you wish to Compact the database, create tables, delete tables, edit tables open Enterprise Manager...so what do you want to do?
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  3. #3
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OK This is how i am doing mine,
    Its working great!

    Declarations:

    VB Code:
    1. Const mySqlHost = "localhost"
    2. Const DataBase = "myDataBase"
    3. Const MySqlUID = "root"
    4. Const MySqlUID = ""

    Usage:

    VB Code:
    1. On Error GoTo Error_Msg:
    2. Dim oConn As New ADODB.Connection
    3. Dim myrs As New Recordset
    4. Dim mySQL As String
    5.  
    6. ' Creating the Connection Socket
    7. oConn.Open "Driver={mySQL};" & _
    8.            "Server=" & mySqlHost & ";" & _
    9.            "Port=3306;" & _
    10.            "Option=131072;" & _
    11.            "Stmt=;" & _
    12.            "Database=" & DataBase & ";" & _
    13.            "Uid=" & MySqlUID & ";" & _
    14.            "Pwd=" & MySqlPass & ";"
    15.  
    16. ' SQL Query to preform,
    17. ' Remember when using WHERE stuff, you need to use ' around stuff like "User" etc.
    18. mySQL = "SELECT uid, uname, pass from " & UserTable & " WHERE uname='" & User & "'"
    19.  
    20. ' Just set the cursor location etc for the record set
    21. myrs.CursorLocation = adUseClient
    22. ' Create the record set By executing the MySQL query (Dont need a record set for Update / Delete / Insert :)
    23. Set myrs = oConn.Execute(mySQL)
    24.  
    25. ' Now, There may be an error if no records are found, if checking The Password agains the password in the Database (myrs("pass"))
    26. On Error GoTo CheckError:
    27.  
    28.     If (myrs("pass") = Password) Then
    29.               ' Do my authorize access here
    30.     Else
    31.               ' Do my unauthorized access here
    32.     End If
    33.  
    34. ' We use a "GoTo" for the error, so i use this for it :)
    35. GoTo CloseUp:
    36.  
    37. Exit Sub
    38.  
    39. CloseUp:
    40.       ' Close the connection
    41.       oConn.close
    42.       ' Created a Object to connect, so lets delete it
    43.       set oConn = Nothing
    44.       ' As well as delete the record set
    45.       set myrs = Nothing
    46. Exit Sub
    47.  
    48. CheckError:
    49.     If Err.Number = 3021 Then ' 3021 = No Records Found
    50.         ' Since no records are found, there isnt a username like dat,
    51.         ' Do failed Login
    52.         GoTo CloseUp:
    53.     Else
    54.         MsgBox Err.Description
    55.         Err.Clear
    56.         Resume Next
    57.     End If
    58. Exit Sub

    REMEMBER: ALWAY DELETE MADE CONTROLS
    ALWAYS CLOSE CONNECTIONS!

    Insert use like:

    VB Code:
    1. SQL = "INSERT INTO " & Table & " (field1, field2, field3) VALUES ('Field1Val', 'Field2Val', 'Field3Val')"

    To do a "While(List(...)...){":

    VB Code:
    1. Do until mrrs.EOF
    2.       ' Use it however you need to here
    3.       txtLog.SelText = myrs("uname") & vbcrlf
    4.       ' Move to the next record
    5.       myrs.MoveNext
    6. Loop


    Hope this helps
    Wayne

  4. #4

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Thx a lot!
    I know SQL statements, but about connecting and stuffs like that,
    can u pls tell me more about it?
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  5. #5
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    VB Code:
    1. 'OK, Lets start on the Basics:
    2.  
    3. ' Names Can be anything, as long as you tell VB What it is!
    4. ' Always Dim it (of course) Before you use it,
    5. ' (Best to do Dimming at the top, unless its a REALLY long function,
    6. ' and with some, its best to create the object as you need it, else Lag-O-Ramma)
    7.  
    8. ' Can use anything as the Connection name:
    9. ' --> Dim oConn As New ADODB.Connection <-- Can be:
    10. Dim MyUsers As New ADODB.Connection
    11. ' Very great for when you need to do more then one Database Connection at a time etc :)
    12.  
    13. ' Same goes for the record set, Can have 6 million or whatever
    14. ' (Doubt any system would handle that much usage tho ;))
    15. Dim myrs As New Recordset
    16.  
    17. ' Just the string (YOU DONT NEED TO DO IT LIKE THIS,
    18. ' SEE LOWER)
    19. Dim mySQL As String
    20.  
    21.  
    22. ' Creating the Connection Socket
    23. ' This is the "ADODB.Connection": YourName.Open
    24.  
    25. ' You can hard code the stuff in, but if you wanna allow the user to change the stuff,
    26. ' on demange, use a INI file or something, but all the same:
    27. oConn.Open "Driver={mySQL};" & _
    28.            "Server=" & mySqlHost & ";" & _
    29.            "Port=3306;" & _
    30.            "Option=131072;" & _
    31.            "Stmt=;" & _
    32.            "Database=" & DataBase & ";" & _
    33.            "Uid=" & MySqlUID & ";" & _
    34.            "Pwd=" & MySqlPass & ";"
    35.  
    36. ' ------------------------------------------------------------
    37.  
    38. MyNewDIMMEDName.Open "Driver={mySQL};" & _
    39.            "Server=MyWebHost.com;" & _
    40.            "Port=" & UseYourMysqlPortNumberHere_Default_3306 & ";" & _
    41.            "Option=131072;" & _
    42.            "Stmt=;" & _
    43.            "Database=MyDataBaseNameHere;" & _
    44.            "Uid=MyMySQLUName;" & _
    45.            "Pwd=*******;"
    46.  
    47. ' NEVER use your "Root" MySQL name for distributed App's,
    48. ' DONT Give em an easy ride ;) Make their Username:
    49. ' SELECT / (Delete if needed) / (Update If Needed) / ETC.
    50. ' Only what they need to do!
    51.  
    52. ' Remember the mySQL was dimmed as String?
    53. mySQL = "SELECT uid, uname, pass from " & UserTable & " WHERE uname='" & User & "'"
    54.  
    55. ' Well, you dont HAVE to do it like this. Doing:
    56. Set myrs = oConn.Execute("SELECT myField1, MyField2 FROM MyTableName Where MyField3='MyNeededSearch'")
    57.  
    58. ' Deleting you can just do:
    59.  oConn.Execute("DELETE FROM .... WHERE .... = ' ... '")
    60. ' Updating Do:
    61.  oConn.Execute("Update ... Set .. = '...' WHERE ...='...'")
    62.  
    63. ' To use your selected Record set:
    64. Text1.Text = myrs("FieldName")
    65.  
    66. ' MySQL (to my knowledge) Doesn't allow you to do row count :(
    67. ' Anyone knows how do do this Properly, Brill ;)
    68. ' I do:
    69. Do Until myrs.EOF
    70. lstRCount.AddItem myrs("field1")
    71. myrs.movenext
    72. Loop
    73. myrs.movefirst
    74.  
    75. Dim Count as Integer
    76. Count = lstRCount.ListCount

    And so on, If you tell me something Specific you need help with, i would be more then happy to (Since There Was quite a few people who helped me) ' No good at "Manual Things"

    I aint no VB MySQL Expert, but it isnt that hard to learn, once you get into it

    I Would say it is easier then PHP / MySQL some of the time (RecordCount is a little sad tho )
    Wayne

  6. #6

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    wpearsall:
    Thx! Thx! Thx!

    I started to understand sumthin'
    but what about the option argument as in the Open method?
    Can u explain 2 me 1 by 1 of all the arguments in the Open
    method?

    And BTW, do u think Access 97 or 2k will allow me to update
    server database (as in this case)?
    Thx a lot!
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  7. #7
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    How do u mean, (Access update?)

    oConn.Open u mean ?


    VB Code:
    1. "Driver={mySQL};" '< Tell the system it needs to connect to a MySQL Server
    2. "Server=" & mySqlHost & ";" '< Tell the System, The Host Name (localhost / MySite.Com / ***.***.***.***)
    3. "Port=3306;" '< Port number too, Since some MySQL Run on a different Port
    4. "Option=131072;"' < This i dont know (Lol)
    5. "Stmt=;" '< Same goes for this
    6. "Database=" & DataBase & ";" ' < What database THIS connection is using (You can make more then one connection (oConn1. oConn2. oConn3 etc, but u gotta dim all of em ;)
    7. "Uid=" & MySqlUID & ";" '< User ID (As i said before, Dont use use Root Access Name(s).. Make a new user (on phpmyadmin, its in the front page "Users") .. Best to be DB Specific, (Security and all ;))
    8. "Pwd=" & MySqlPass & ";" '< Password.  U can set this to "Pwd=;" if it is PW-less ;)


    ADO + Access though, not got to dat part yet (I was starting to use it, but opted for MySQL, Since my user-base is MySQL)

    But basically the same, (There is a few differences etc tho)

    OH And BTW,:

    [sql]
    Where MyField != 'myval'
    [/sql]

    Dat results in, ??? WHERE The Value of MyField IS NOT myval (Just like PHP

    OH BTW, Did u Install the myODBC Driver for MySQL yet?
    Wayne

  8. #8

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Uh...not sure 'bout that.

    By Access I meant Microsoft Access. Does it allow me to update
    my online database? If yes, things will be simpler
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width