connect_example.c 664 字节
Newer Older
1
// compile with
B
Bo Ding 已提交
2
// gcc connect_example.c -o connect_example -ltaos
3
#include <stdio.h>
B
Bo Ding 已提交
4
#include <stdlib.h>
5 6 7
#include "taos.h"

int main() {
B
Bo Ding 已提交
8 9 10 11
  const char *host = "localhost";
  const char *user = "root";
  const char *passwd = "taosdata";
  // if don't want to connect to a default db, set it to NULL or ""
12
  const char *db = NULL;
B
Bo Ding 已提交
13 14 15
  uint16_t    port = 0;  // 0 means use the default port
  TAOS       *taos = taos_connect(host, user, passwd, db, port);
  if (taos == NULL) {
D
dingbo 已提交
16
    int   errno = taos_errno(NULL);
17
    char *msg = taos_errstr(NULL);
D
dingbo 已提交
18
    printf("%d, %s\n", errno, msg);
B
Bo Ding 已提交
19 20 21 22 23
  } else {
    printf("connected\n");
    taos_close(taos);
  }
  taos_cleanup();
24
}