Results 1 to 11 of 11

Thread: PHP sample to work with VB please

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    Exclamation PHP sample to work with VB please

    I'm looking for some examples of code for a php script to work with visual basic 6.0 and the VB code to work with it. If you have any or know where I can get some, please share. Thank you ahead of time.

    Teafour

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    What are you talking about?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    Sorry.. I wrote that in the midst of two other things and missed the details of what I'm trying to do.. I am working on a program in Visual basic 6.0.. I'm new to it.. I'm only slightly more familiar with PHP.. what I want to do is interact with a MySQL database using php with my Visual Basic program. The example of the data I want to pass back and forth would be to use the VB login and password to send data to a php script of which verifies the data in the database for username and password and then returns a recordset of information that would be put into variables in VB. Once a person is logged into the client.. I would want to pass data to through PHP to the DB telling it selections the person made in the VB program. Does that explain what I'm trying to do better??..

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You can interact with the MySQL server without PHP. I don't know how to do it, but I know you can.

    I know you could use a winsock and just connect to your host, then send the commands if it's setup for it. Ask in the VB forum about interacting with a MySQL server. I'm sure you'll get responses.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    I know that on a lan or such that we can use a winsock to communicate with the MySQL DB directly however the hosting services out there restrict external access to the DB directly and only allow webacces via php, cgi or the like base on your hosting service. Most let you use PHPAdmin to work with the DB which makes it so I can't use a DAO in Visual Basic or anything to directly access.. so I have to go through PHP or a CGI script to pass it back and forth.. which as you can see, is out of my realm of knowledge..

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Dinz
    I had recently developed an application in VB which directly communicates with MySql database residing in Linux server......if these is what u r looking then let me know may be I can help u...
    He already said that his host wont allow external connection to the server...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    I would love to take a look at what you have working with the MySQL db just to see how it works and wether I can get it working for me.. now on that note.. I had an idea.. what I'm trying to do is update information as people make selections in the VB program and was thinking.. in VB I can have a webbrowser window that is invisible and just have it open a webpage passing variables to it as if it was typed in the HTTP Address line.. does that make any sense and do you think it might work?

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Instead of doing all that, you could just download the source of the page, like:

    http://www.yoursite.com/data.php?action=insert&id=5

    VB Code:
    1. Option Explicit
    2.  
    3. Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    4.   (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
    5.   ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    6.  
    7. Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" _
    8.   (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, _
    9.   ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
    10.  
    11. Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, _
    12.   ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) _
    13.   As Integer
    14.  
    15. Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) _
    16.   As Integer
    17.  
    18. Public Const IF_FROM_CACHE = &H1000000
    19. Public Const IF_MAKE_PERSISTENT = &H2000000
    20. Public Const IF_NO_CACHE_WRITE = &H4000000      
    21. Private Const BUFFER_LEN = 256
    22.  
    23. Public Function GetUrlSource(sURL As String) As String
    24. Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String
    25. Dim hInternet As Long, hSession As Long, lReturn As Long
    26.  
    27.     hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
    28.     If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, _
    29.       IF_NO_CACHE_WRITE, 0)
    30.  
    31.     If hInternet Then
    32.         iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
    33.         sData = sBuffer
    34.         Do While lReturn <> 0
    35.             iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
    36.             sData = sData + Mid(sBuffer, 1, lReturn)
    37.         Loop
    38.     End If    
    39.  
    40.     iResult = InternetCloseHandle(hInternet)
    41.     GetUrlSource = sData
    42. End Function

    That would technically navigate to the site, then give you the source of the result. So in data.php, if it's a success, have it echo "success" and then just:

    VB Code:
    1. strResult = GetUrlSource("http://www.yoursite.com/data.php?action=insert&id=5")
    2.  
    3. If strResult = "success" Then
    4.   MsgBox "Data Entered!"
    5. End If
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    Thanks Hobo.. I'm going to try and work with this some for awhile.. it's a bit over my head with VB because it's as elaborate as it is.. however once I start breaking it down it'll make more sense to me I'm sure.. If I have no luck I will post again in here later.

    Teafour

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Here's an easy example, just for fun:

    VB Code:
    1. Private Sub Form_Load()
    2. Dim strSend As String, strResult As String
    3.  
    4.   strSend = InputBox("Action:", "Action")
    5.  
    6.   strResult = GetUrlSource("http://www.site.com/work.php?action=" & strSend)
    7.  
    8.   MsgBox strResult
    9.  
    10. End Sub

    And for work.php (needs to be accessable on the net):

    PHP Code:
    <?php

    if ($action == 'boo') {
        echo 
    'foooah!';
    }else {
        echo 
    'bah!';
    }

    ?>
    That's probably about the simplest example there. Working with databases would be a little trickier:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim strSend As String, strResult As String
    5. Dim i As Integer, lns() As String
    6.  
    7.   strSend = "display"
    8.   strResult = GetUrlSource("http://www.site.com/work.php?action=" & strSend)
    9.  
    10.   If Trim(strResult) <> "failure" Then
    11.     lns() = Split(strResult, vbLf)
    12.     For i = 0 To UBound(lns) - 1
    13.       List1.AddItem lns(i)
    14.     Next
    15.   End If
    16. End Sub

    And for the PHP:

    PHP Code:
    <?php
    $db 
    mysql_connect("localhost""user""pass") or die(mysql_error());
    mysql_select_db("database"$db) or die(mysql_error());

    if (
    $action == 'display') {
        
    $sql "SELECT * FROM table";
        
    $result mysql_query($sql$db);
        if (
    $myrow mysql_fetch_array($result)) {
            do {
                echo 
    $myrow["name"] . "\n";
            } while (
    $myrow mysql_fetch_array($result));
        } else {
            echo 
    "failure";
        }
    }
    Something like that.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    scoutt
    Guest
    that's pretty cool hobo. why don't you add that to my database at my site?? hint hint

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