Results 1 to 8 of 8

Thread: query remote sql

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    185

    query remote sql

    I want to get information from remote mysql database from my VB6 Application.
    I want to use PHP, because mysql database don't accept remote access.
    I've seen an Example and then I try but not seccessfull.
    Can anybody help me?

    Hare i want to check the db for, is there available my name? yes or not Just It.

    VB Code:
    1. sql = "Select * FROM usrtbl Where name='" & Text1.txt & "'"
    2.         path = "http://localhost/name.php?sql="
    3.         myPath = path & sql
    4.         MyIP = Inet1.OpenURL(myPath)
    5.         Text1.Text = MyIP

    PHP Code:
    <?php
    $host
    ="localhost";
    $user="root";
    $db="ant";
    $link=mysql_connect($host,$user) or die ("Couldnot connect".mysql_error());
    if (
    $link) {
        
    mysql_select_db($db) or die ("Couldn't".mysql_error());
        }
        
    $result=mysql_query('sql'); 

        
    $num_rows=mysql_num_rows($result);
        if (
    $num_rows 0)
        {
        print
    "1";
        }else{
        print
    "0";
        }
    ?>

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: query remote sql

    What is it that you want help in? VB6 or PHP?

  3. #3
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    396

    Re: query remote sql

    Hi r_amin;

    I am a bit baffled by your request.

    I want to get information from remote mysql database from my VB6 Application.

    If the five lines of code you've shown are all you are working with then you need to do more work. Where is your connection string? You say you want to connect to a remote database but you use localhost???

    What is the purpose of Text1.Text in your sql = statement and it's relationship to Text1.Text = MyIP in the last statement

    Does MyIP = Inet1.OpenURL(myPath) return an IP address like 192.168.1.1?

    I want to use PHP, because mysql database don't accept remote access.
    Could you provide additional detail, as far as I know you can connect remotely to a MySQL database.

    I've seen an Example and then I try but not seccessfull.
    What exactly are you trying to do?

    Can anybody help me?
    Please provide more information.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    185

    Re: query remote sql

    Quote Originally Posted by Hack
    What is it that you want help in? VB6 or PHP?
    Both.

    I'm trying VB6 + PHP.
    please read, I think, I've told everything detailed.

    actually I need to know, Is there my name in the database? Yes or not.
    when any host not support remote access, So I need another way.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    185

    Re: query remote sql

    Hi LinXG
    Yes, this is localhost. This is my practice. But, I want to apply it to remote host.
    ''Text1.Text'' is used to enter a name. What i want to find.
    MyIP just a string veriable
    Yes, I can connect remotely to a MySQL database, But not any Database anytime. It has restriction.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    185

    Re: query remote sql

    as we can know IP address

    Dim MyIP As String
    MyIP = Inet1.OpenURL("http://pchelplive.com/ip.php")
    Text1.Text = MyIP
    Text1.Text = Replace(Text1, Chr(10), "")

  7. #7
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    396

    Re: query remote sql

    Hi r_amin

    I'm still not sure what you're after but here is a code sample that shows how to connect a MySQL database and retrieve some data using VB6.

    Code:
    Dim MyRecordSet As ADODB.Recordset
    Dim mySQL_String As String
    Dim StrConn as String
    
    ' **** Use of one these statements, comment out the other ****
    
    StrConn = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDataBase; User=myUsername;Password=myPassword;Option=3;"				' Localhost connection 
    StrConn = "Driver={MySQL ODBC 3.51 Driver};Server=data.domain.com;Port=3306;Database=myDataBase;User=myUsername; Password=myPassword;Option=3;"		' Remote connection 
    
    mySQL_String = "Select * FROM usrtbl Where name='" & Text1.txt & "'"
    Set MyRecordSet = New ADODB.Recordset
    MyRecordSet.Open mySQL_String, StrConn, , , adCmdUnknown
    
    
    If MyRecordSet.EOF = False then
     ' If the recordset is not empty do something
     Text2.text = MyRecordSet("SomeFieldName")		' example - show a field in a text box
    else
     ' If the recordset is empty do this instead
    end if
    
    MyRecordSet.Close

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: query remote sql

    Quote Originally Posted by LinXG
    Hi r_amin

    I'm still not sure what you're after but here is a code sample that shows how to connect a MySQL database and retrieve some data using VB6.
    Except that.....

    Quote Originally Posted by r_amin
    I want to use PHP, because mysql database don't accept remote access.
    So connecting directly via vb6 ain't gonna cut it...

    The problem is the SQL statement itself.... in a nutshell, you are sending it as is, but using the QueryString to send it.... It has to be URL encoded first... then from the PHP site, retrieved using the GET[] vars, and DeURLEncoded. I know there's a function in PHP that will undo the url encoding....I'm reasonably sure there isn't a built-in VB6 way to do it, but there are components out there that can do it. Search for VB6 URLEncoding or Visual Basic URLENcoding, and other variations, something is bound to turn up.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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