Use VB to initiate a socket connection to PHP.

I have a VB program that I would like to talk to my webserver. The catch is, I want the VB program to initiate the connection. I am sure I have to use socket programming, but I don't know how to do it. Can you guys help?
LVL 32
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There are several technologies you can use to access your web server from VB.

For example, there are the WinInet API calls.
Return the Contents of a Web Page Using WinInet API

Here's a nice class that handles the posting of data to a webserver via WinInet.  I assume you will be doing something similar.

You can use the Winsock to handle this as well, but it's very low level.  You have to know the HTTP protocol fairly intimately to construct the calls.
How to download a file from the Web server

There are other components you can use as well.  If you give me an idea what your needs are, I can whip up some examples.
DrDamnitAuthor Commented:
I just need to pass MySQL query strings to the internet server. That server must catch the query calls, and then execute them using PHP. The result set must then be downloaded back to the VB client.

Does that make it more clear?
Sure.  So you'll want to do an HTTP post operation to your php script.  You could use the HTTP class to do that, or if you're going to be sending back information as XML, you can use the XMLHTTP component, which is built into the XML libary from Microsoft.

Option Explicit

Private Sub Command1_Click()
    Set oXmlHTTP = New XMLHTTP
    Dim strPostData As String
    strPostData = "query=" & fURLEncode("Select * From Table") "POST", "", False
    oXmlHTTP.send strPostData
    Debug.Print oXmlHTTP.responseXML

End Sub

Public Function fURLEncode(strToEncode As String) As String
    Dim strTemp As String
    Dim lngLen As Long
    Dim intASC As Integer
    Dim i As Long
    lngLen = Len(strToEncode)
    For i = 1 To lngLen
        intASC = Asc(Mid$(strToEncode, i, 1))
        'Is the character in the list of valid chars?  Use alphanumerics only to be very very safe.
        If InStr(1, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", Chr(intASC)) Then  '$-_.!*'(),
            strTemp = strTemp & Chr(intASC)
            If intASC < 16 Then
                strTemp = strTemp & "%0" & Hex(intASC)
                strTemp = strTemp & "%" & Hex(intASC)
            End If
        End If
    Next i
    fURLEncode = strTemp

End Function

Hopefully you're going to put in some kind of security so that no one can just submit "Drop Table"  or whatever.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DrDamnitAuthor Commented:
Sounds like what I need....I'll try that and get back to you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.