Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: chris smith
  Where is chris smith?
 Yorkshire CH CH
 Barbados
 chris smith
 Tags
Subject: RE: updateing a mySQL database
Thread ID: 311071 Message ID: 311076 # Views: 60 # Ratings: 3
Version: Visual FoxPro 6 Category: Off-topic
Date: Tuesday, June 28, 2011 4:45:36 PM         
   


> Hello Guys
>
> I have a mySql database on a file server and I would like to insert a record into a table in the database from a VFP app via the internet....
>
> How can I go this?
>
> thanks in advance
>
> Chris Smith

First you need to have a connection string. You would use either ODBC or OLEDB connection string depending on what you are using (my preference is OLEDB). You can find the connection strings here:

http://www.connectionstrings.com/mysql

Then with ODBC it is something like:

handle = SQLStringConnect( < your connection string here > )
lcCommand = 'insert into myTable (field1, field2) values (?m.v1, ?m.v2)'

v1 = "String value"
v2 = datetime()

SQLExec(m.handle, m.lcCommand)

SQLDisconnect(m.handle)


Using OLEDB you can use ADO. It is harder at first but I think better on the long run. ie (with testdata.dbc - you can use this to utilize VFP9 engine for example, because VFPOLEDB provider is built upon VFP9 engine):

Note: With MySQL you would have a different ConnectionString (and SQL may be slightly different but in general rest is same)

Local loRS As ADODB.Recordset, ;
  loCon As ADODB.Connection, ;
  loCmd As ADODB.Command

loCon = Createobject("ADODB.Connection")
loCmd = Createobject('ADODB.Command')
loRS  = Createobject("ADODB.RecordSet")
With loCon
  .ConnectionString = "Provider=VFPOLEDB;Data Source="+_samples+"data\TESTDATA.DBC"
  .Mode = 16  && adModeShareDenyNone
  .Open()
Endwith
With loCmd
  .ActiveConnection = loCon
  .CommandType = 2	&& Table
  .CommandText = 'customer'
Endwith
With loRS
  .CursorType 	= 2		&& ADOPENDYNAMIC
  .LockType 	= 4		&& ADLOCKBATCHOPTIMISTIC
  .CursorLocation = 3		&& ADUSECLIENT
  .ActiveConnection = loCon
  .Open(loCmd)
Endwith

loCon.Execute("set null off")

loRS.AddNew
loRS.Fields("Cust_ID").Value = "ADO1"
loRS.AddNew
loRS.Fields("Cust_ID").Value = "ADO2"
loRS.UpdateBatch()
loRS.Close()
loCon.Close()


Cetin Basoz

.Net has got better.Think about moving - check my blog:
My Blog
Blog (mirror) - sounds to be down

ENTIRE THREAD

updateing a mySQL database Posted by chris smith @ 6/28/2011 4:07:52 PM
RE: updateing a mySQL database Posted by Cetin Basoz @ 6/28/2011 4:45:36 PM
RE: updateing a mySQL database Posted by chris smith @ 6/28/2011 8:14:28 PM
RE: updateing a mySQL database Posted by Cetin Basoz @ 6/28/2011 10:58:08 PM
RE: updateing a mySQL database Posted by chris smith @ 6/29/2011 4:27:06 AM
RE: updateing a mySQL database Posted by Cetin Basoz @ 6/29/2011 7:09:54 PM
RE: updateing a mySQL database Posted by Cody Leaf @ 6/29/2011 7:44:54 PM
RE: updateing a mySQL database Posted by Mike Yearwood @ 6/29/2011 4:36:13 PM
RE: updateing a mySQL database Posted by chris smith @ 6/29/2011 5:34:17 PM