connect_example.c 602 字节
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 16 17 18 19 20 21
  uint16_t    port = 0;  // 0 means use the default port
  TAOS       *taos = taos_connect(host, user, passwd, db, port);
  if (taos == NULL) {
    printf("failed to connect to server\n");
  } else {
    printf("connected\n");
    taos_close(taos);
  }
  taos_cleanup();
22
}