//初始化数据结构
&&mysql_real_connect(myData,NULL,
//连接数据库
"root","your_password",szTargetDSN,
MYSQL_PORT,NULL,0))
{
if(bCreate)
{
sprintf(szSqlText,//构造SQL语句
"createtablemytable"
//新建一张表
"(timedatetime,s1char(6),"
"s2char(11),s3int,s4int)");
if(mysql_query(myData,szSqlText))
//执行SQL语句
{//执行SQL语句出错
ErrLog("Can'tcreatetable");
mysql_close(myData);
returnFALSE;
}
}
sprintf(szSqlText,
"insertintomytable"
//向表中插入数据
"values('2000-3-1021:01:30',"
//注意时间的格式
"'Test','MySQLTest',2000,3)");
if(mysql_query(myData,szSqlText))
{//执行SQL语句出错
ErrLog("Can'tinsertdatatotable");
mysql_close(myData);
returnFALSE;
}
sprintf(szSqlText,"select*frommytable");
if(mysql_query(myData,szSqlText))
//进行数据检索
{
//执行SQL语句出错
mysql_close(myData);
returnFALSE;
}
else
{
res=mysql_store_result(myData);
//取得查询结果
i=(int)mysql_num_rows(res);
//取得有效记录数
printf("Query:%s %ldrecordsfound:
",szSqlText,i);
for(i=0;fd=mysql_fetch_field(res);
--转自