打印本文 打印本文 关闭窗口 关闭窗口
MySQL数据库学习笔记(三)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3591  更新时间:2009/4/22 20:49:06  文章录入:mintao  责任编辑:mintao

附录一 Mytest.c

/****************************************************************/

/*    Author:    Allen Lee TS :  2/ 4/2004  9:15   */

/*    Date:       2/ 4/2004                                   */

/*    mytest.c :  test DDL statment*/

/*                                                     */

/*    History:                                      */

/*                  */

/****************************************************************/

 

 

#include  <windows.h>

#include  <stdio.h>

#include  <string.h>

 

#include  <mysql.h>

#define STRING_SIZE 50

 

#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table"

#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT,\

                                                 col2 VARCHAR(40),\

                                                 col3 SMALLINT,\

                                                 col4 TIMESTAMP)"

#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2,col3) VALUES(?,?,?)"

 

int main(int argc, char **argv){

 

       MYSQL *mysql;

 

       mysql = mysql_init(NULL);

       if(!mysql_real_connect(mysql, "localhost","root","","",3306,"",NULL)){ /* Make connection with mysql_connect(MYSQL db, char *host, char *username, char *password */

       printf(mysql_error(mysql));

       exit(1);

       }

 

       if(mysql_select_db(mysql, "test")){ /* Select the database we want to use */

       printf(mysql_error(mysql));

       exit(1);

       }

 

       MYSQL_STMT    *stmt;

       MYSQL_BIND    bind[3];

       my_ulonglong  affected_rows;

       int           param_count;

       short         small_data;

       int           int_data;

       char          str_data[STRING_SIZE];

       unsigned long str_length;

       my_bool       is_null;

 

       if (mysql_query(mysql, DROP_SAMPLE_TABLE))

       {

         fprintf(stderr, " DROP TABLE failed\n");

         fprintf(stderr, " %s\n", mysql_error(mysql));

         exit(0);

&nbs

[1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口