Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySQL - Database to sample?
#9
Below is some LCC-Win32 code that I have adapted to my needs.
It opens a .mdb database file on my computer.....all is well.

Question: Would I just change the DSN string to connect to a file
not on my computer? If so, what would the connection string be....There must be at least one file out there that is public, that I can connect to surely. For example. If I want to open a file on my computer I use Open(), Create() etc to work on that file. If I want
to open/retrieve a file from my website I use "Internet (FTP) API".
So if I am now using the code below to open a .mdb file on my computer then surely there must be a way (APIwise) to connect to an outside file on a server.

Regards

John



// Link with odbc32.lib and libmysql.lib

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql.h>
#include <mysql_com.h>
#include <mysql_version.h>
#include <sql.h>
#include <sqlext.h>

#define STG_LEN 256

int main(int argc,char *argv[])
{
SQLRETURN retcode=0;
HENV hEnvironment=SQL_NULL_HANDLE;
HDBC hConnection=SQL_NULL_HANDLE;
HSTMT hStatement=SQL_NULL_HSTMT;
long id=0;
char szString[STG_LEN];
char szSql[STG_LEN];
char szout[STG_LEN];
char connectionString[]="DSN=MS Access Database;DBQ=PersonalDetails.mdb;FIL=MS Access;";

retcode=SQLAllocEnv(&hEnvironment);
if (retcode==SQL_SUCCESS)
{
retcode=SQLAllocConnect(hEnvironment,&hConnection);
if (retcode==SQL_SUCCESS)
{
retcode=SQLDriverConnect(hConnection,NULL,(SQLCHAR *)connectionString,(short)(strlen(connectionString)+1),NULL,0,NULL,SQL_DRIVER_NOPROMPT);
if (retcode==SQL_SUCCESS)
{
retcode=SQLAllocStmt(hConnection,&hStatement);
if (retcode==SQL_SUCCESS)
{

lstrcpy(szSql,"SELECT * FROM Contacts ORDER BY RecordID");
retcode=SQLExecDirect(hStatement,szSql,SQL_NTS);
if (retcode==SQL_SUCCESS)
{
while (retcode=SQLFetch(hStatement)==SQL_SUCCESS)
{

retcode=SQLGetData(hStatement,1,SQL_C_DEFAULT,&id,0,NULL);
if (retcode==SQL_SUCCESS)
{

memset(szString,0,STG_LEN);
retcode=SQLGetData(hStatement,2,SQL_CHAR,szString,STG_LEN,NULL);
if (retcode==SQL_SUCCESS)
{
fprintf(stdout, "ID: %d\tString1: %s\n",id,szString);
}
}
}
}



SQLFreeStmt(hStatement,SQL_DROP);
}
SQLDisconnect(hConnection);
}
SQLFreeConnect(hConnection);
}
SQLFreeEnv(hEnvironment);
}
return 0;
}
Reply


Messages In This Thread
MySQL - Database to sample? - by yoingco - 02-12-2005, 05:09 AM
MySQL - Database to sample? - by yoingco - 02-12-2005, 05:12 PM
MySQL - Database to sample? - by yoingco - 02-12-2005, 05:44 PM
MySQL - Database to sample? - by yoingco - 02-12-2005, 05:49 PM
MySQL - Database to sample? - by KiZ - 02-12-2005, 07:02 PM
MySQL - Database to sample? - by yoingco - 02-12-2005, 09:35 PM
MySQL - Database to sample? - by whitetiger0990 - 02-12-2005, 09:40 PM
MySQL - Database to sample? - by yoingco - 02-13-2005, 01:13 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)