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ɹ ִ ɹ Ʈ ϵ . ɼ CLIENT_MULTI_RESULTS Ȱȭ Ű , mysql_real_connect() CLIENT_MULTI_STATEMENTS flags μ CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS μ ȴ. , CLIENT_MULTI_STATEMENTS Լ ϴ Ƽ-ɹ Ƽ- μ ó ִ.
  • Ŀ mysql_set_server_option() Լ ؼ Ƽ-ɹ Ȱȭ Ǵ Ȱȭ ų ִ.

Ʒ Ƽ-ɹ ó ϴ ϴ ̴:

1.     CLIENT_MULTI_STATEMENTS mysql_real_connect() ؼ Ƽ-ɹ Ƽ- μ ü Ȱȭ Ų.

2.     mysql_query() Ǵ mysql_real_query() ȣ Ŀ, ɹ ԷѴ.

3.     ݺ ɹ óϰ, Ǵ ī带 Ѵ. ߻Ѵٸ, Ѵ.

4.     mysql_next_result() ȣؼ ٸ ִ ˻ Ŀ ִٸ װ Ѵ. ̻ ʴٸ, Ѵ.

 

Ѵ.

 

/* connect to server with option CLIENT_MULTI_STATEMENTS */

if (mysql_real_connect (mysql, host_name, user_name, password,

    db_name, port_num, socket_name, CLIENT_MULTI_STATEMENTS) == NULL)

{

  printf("mysql_real_connect() failed\n");

  mysql_close(mysql);

  exit(1);

}

 

/* execute multiple statements */

status = mysql_query(mysql,

                     "DROP TABLE IF EXISTS test_table;\

                      CREATE TABLE test_table(id INT);\

                      INSERT INTO test_table VALUES(10);\

                      UPDATE test_table SET id=20 WHERE id=10;\

                      SELECT * FROM test_table;\

                      DROP TABLE test_table");

if (status)

{

  printf("Could not execute statement(s)");

  mysql_close(mysql);

  exit(0);

}

 

/* process each statement result */

do {

  /* did current statement return data? */

  result = mysql_store_result(mysql);

  if (result)

  {

    /* yes; process rows and free the result set */

    process_result_set(mysql, result);

    mysql_free_result(result);

  }

  else          /* no result set or error */

  {

    if (mysql_field_count(mysql) == 0)

    {

      printf("%lld rows affected\n",

            mysql_affected_rows(mysql));

    }

    else  /* some error occurred */

    {

      printf("Could not retrieve result set\n");

      break;

    }

  }

  /* more results? -1 = no, >0 = error, 0 = yes (keep looping) */

  if ((status = mysql_next_result(mysql)) > 0)

    printf("Could not execute statement\n");

} while (status == 0);

 

mysql_close(mysql);

24.2.9. C API Ƽ ɹ
MySQL Korea Ʈ ()̺ Ƿ 縦 մϴ.
2010-2011 ssebiz All Rights Reserved.