|
-
May 12th, 2002, 11:07 AM
#1
Thread Starter
New Member
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
-
May 12th, 2002, 08:36 PM
#2
Stuck in the 80s
What are you talking about?
-
May 12th, 2002, 11:06 PM
#3
Thread Starter
New Member
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??..
-
May 13th, 2002, 10:47 AM
#4
Stuck in the 80s
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.
-
May 13th, 2002, 11:14 AM
#5
Thread Starter
New Member
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..
-
May 14th, 2002, 01:48 PM
#6
Stuck in the 80s
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...
-
May 15th, 2002, 04:53 PM
#7
Thread Starter
New Member
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?
-
May 16th, 2002, 02:01 PM
#8
Stuck in the 80s
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:
Option Explicit
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" _
(ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, _
ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, _
ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) _
As Integer
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) _
As Integer
Public Const IF_FROM_CACHE = &H1000000
Public Const IF_MAKE_PERSISTENT = &H2000000
Public Const IF_NO_CACHE_WRITE = &H4000000
Private Const BUFFER_LEN = 256
Public Function GetUrlSource(sURL As String) As String
Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String
Dim hInternet As Long, hSession As Long, lReturn As Long
hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, _
IF_NO_CACHE_WRITE, 0)
If hInternet Then
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sBuffer
Do While lReturn <> 0
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sData + Mid(sBuffer, 1, lReturn)
Loop
End If
iResult = InternetCloseHandle(hInternet)
GetUrlSource = sData
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:
strResult = GetUrlSource("http://www.yoursite.com/data.php?action=insert&id=5")
If strResult = "success" Then
MsgBox "Data Entered!"
End If
-
May 16th, 2002, 09:33 PM
#9
Thread Starter
New Member
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
-
May 17th, 2002, 01:03 PM
#10
Stuck in the 80s
Here's an easy example, just for fun:
VB Code:
Private Sub Form_Load()
Dim strSend As String, strResult As String
strSend = InputBox("Action:", "Action")
strResult = GetUrlSource("http://www.site.com/work.php?action=" & strSend)
MsgBox strResult
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:
Option Explicit
Private Sub Command1_Click()
Dim strSend As String, strResult As String
Dim i As Integer, lns() As String
strSend = "display"
strResult = GetUrlSource("http://www.site.com/work.php?action=" & strSend)
If Trim(strResult) <> "failure" Then
lns() = Split(strResult, vbLf)
For i = 0 To UBound(lns) - 1
List1.AddItem lns(i)
Next
End If
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.
-
May 17th, 2002, 01:25 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|