MySQL API

C API Data Structures

  • MYSQL

This structure represents handler for one database connection. It is used for almost all MySQL functions. Do not try to make a copy of a MYSQL structure. There is no guarantee that such a copy will be usable.

  • MYSQL_RES

This structure represents the result of a query that returns rows (SELECT, SHOW, DESCRIBE, EXPLAIN). The information returned from a query is called the result set in the remainder of this section.

  • MYSQL_ROW

This is a type-safe representation of one row of data. It is currently implemented as an array of counted byte strings. (You cannot treat these as null-terminated strings if field values may contain binary data, because such values may contain null bytes internally.) Rows are obtained by calling mysql_fetch_row().

  • MYSQL_FIELD

This structure contains metadata: information about a field, such as the field's name, type, and size. Its members are described in more detail later in this section. You may obtain the MYSQL_FIELD structures for each field by calling mysql_fetch_field() repeatedly. Field values are not part of this structure; they are contained in a MYSQL_ROW structure.

  • MYSQL_FIELD_OFFSET

This is a type-safe representation of an offset into a MySQL field list. (Used by mysql_field_seek().) Offsets are field numbers within a row, beginning at zero.

  • my_ulonglong
  • The type used for the number of rows and for mysql_affected_rows(), mysql_num_rows(), and mysql_insert_id(). This type provides a range of 0 to 1.84e19.
  • Some functions that return a row count using this type return -1 as an unsigned value to indicate an error or exceptional condition. You can check for -1 by comparing the return value to (my_ulonglong)-1 (or to (my_ulonglong)~0, which is equivalent).
  • On some systems, attempting to print a value of type my_ulonglong does not work. To print such a value, convert it to unsigned long and use a %lu print format. Example:
printf ("Number of rows: %lu\n",
(unsigned long) mysql_num_rows(result));
  • my_bool
  • A boolean type, for values that are true (nonzero) or false (zero).
  • The MYSQL_FIELD structure contains the members described in the following list. The definitions apply primarily for columns of result sets such as those produced by SELECT statements. MYSQL_FIELD structures are also used to provide metadata for OUT and INOUT parameters returned from stored procedures executed using prepared CALL statements. For such parameters, some of the structure members have a meaning different from the meaning for column values.
  • char * name

The name of the field, as a null-terminated string. If the field was given an alias with an AS clause, the value of name is the alias. For a procedure parameter, the parameter name.

  • char * org_name

The name of the field, as a null-terminated string. Aliases are ignored. For expressions, the value is an empty string. For a procedure parameter, the parameter name.

  • char * table

The name of the table containing this field, if it is not a calculated field. For calculated fields, the table value is an empty string. If the column is selected from a view, table names the view. If the table or view was given an alias with an AS clause, the value of table is the alias. For a UNION, the value is the empty string. For a procedure parameter, the procedure name.

  • char * org_table

The name of the table, as a null-terminated string. Aliases are ignored. If the column is selected from a view, org_table names the view. For a UNION, the value is the empty string. For a procedure parameter, the procedure name.

  • char * db

The name of the database that the field comes from, as a null-terminated string. If the field is a calculated field, db is an empty string. For a UNION, the value is the empty string. For a procedure parameter, the name of the database containing the procedure.

  • char * catalog

The catalog name. This value is always "def".

  • char * def

The default value of this field, as a null-terminated string. This is set only if you use mysql_list_fields().

  • unsigned long length
  • The width of the field. This corresponds to the display length, in bytes.
  • The server determines the length value before it generates the result set, so this is the minimum length required for a data type capable of holding the largest possible value from the result column, without knowing in advance the actual values that will be produced by the query for the result set.
  • unsigned long max_length
  • The maximum width of the field for the result set (the length in bytes of the longest field value for the rows actually in the result set). If you use mysql_store_result() or mysql_list_fields(), this contains the maximum length for the field. If you use mysql_use_result(), the value of this variable is zero.
  • The value of max_length is the length of the string representation of the values in the result set. For example, if you retrieve a FLOAT column and the “widest” value is -12.345, max_length is 7 (the length of '-12.345').
  • If you are using prepared statements, max_length is not set by default because for the binary protocol the lengths of the values depend on the types of the values in the result set. (See Section 23.8.9, “C API Prepared Statement Data Structures”.) If you want the max_length values anyway, enable the STMT_ATTR_UPDATE_MAX_LENGTH option with mysql_stmt_attr_set() and the lengths will be set when you call mysql_stmt_store_result(). (See Section 23.8.11.3, “mysql_stmt_attr_set()”, and Section 23.8.11.28, “mysql_stmt_store_result()”.)
  • unsigned int name_length

The length of name.

  • unsigned int org_name_length

The length of org_name.

  • unsigned int table_length

The length of table.

  • unsigned int org_table_length

The length of org_table.

  • unsigned int db_length

The length of db.

  • unsigned int catalog_length

The length of catalog.

  • unsigned int def_length

The length of def.

  • unsigned int flags

Bit-flags that describe the field. The flags value may have zero or more of the bits set that are shown in the following table.

C API Function Overview

my_init()
//Initialize global variables, and thread handler in thread-safe programs mysql_affected_rows()
//Returns the number of rows changed/deleted/inserted by the last UPDATE, DELETE, or INSERT query
//返回被最新的UPDATE, DELETE或INSERT查询影响的行数。 mysql_autocommit()
//Toggles autocommit mode on/off mysql_change_user()
//Changes user and database on an open connection
//改变在一个打开的连接上的用户和数据库。 mysql_character_set_name()
// Return default character set name for current connection mysql_client_find_plugin()
// Return pointer to plugin mysql_client_register_plugin()
// Register a plugin mysql_close()
// Closes a server connection
//关闭一个服务器连接。 mysql_commit()
// Commits the transaction mysql_connect()
// Connects to a MySQL server (this function is deprecated; use mysql_real_connect() instead)
//连接一个MySQL服务器。该函数不推荐;使用mysql_real_connect()代替。 mysql_create_db()
// Creates a database (this function is deprecated; use the SQL statement CREATE DATABASE instead)
// 创建一个数据库。该函数不推荐;而使用SQL命令CREATE DATABASE。
mysql_data_seek()
// Seeks to an arbitrary row number in a query result set
//在一个查询结果集合中搜寻一任意行。 mysql_debug()
// Does a DBUG_PUSH with the given string
//用给定字符串做一个DBUG_PUSH。 mysql_drop_db()
// Drops a database (this function is deprecated; use the SQL statement DROP DATABASE instead)
//抛弃一个数据库。该函数不推荐;而使用SQL命令DROP DATABASE。 mysql_dump_debug_info()
// Makes the server write debug information to the log
//让服务器将调试信息写入日志文件。
mysql_eof()
// Determines whether the last row of a result set has been read (this function is deprecated; mysql_errno() or mysql_error() may be used instead)
//确定是否已经读到一个结果集合的最后一行。这功能被反对; mysql_errno()或mysql_error()可以相反被使用。 mysql_errno()
// Returns the error number for the most recently invoked MySQL function
//返回最近被调用的MySQL函数的出错编号。 mysql_error()
// Returns the error message for the most recently invoked MySQL function
//返回最近被调用的MySQL函数的出错消息。 mysql_escape_string()
// Escapes special characters in a string for use in an SQL statement
//用在SQL语句中的字符串的转义特殊字符。 mysql_fetch_field()
// Returns the type of the next table field
//返回下一个表字段的类型。 mysql_fetch_field_direct()
//Returns the type of a table field, given a field number
//返回一个表字段的类型,给出一个字段编号。 mysql_fetch_fields()
// Returns an array of all field structures
//返回一个所有字段结构的数组。 mysql_fetch_lengths()
// Returns the lengths of all columns in the current row
// /返回当前行中所有列的长度。 mysql_fetch_row()
// Fetches the next row from the result set
//从结果集合中取得下一行。 mysql_field_count()
// Returns the number of result columns for the most recent statement
//返回最近查询的结果列的数量。 mysql_field_seek()
// Puts the column cursor on a specified column
//把列光标放在一个指定的列上。 mysql_field_tell()
// Returns the position of the field cursor used for the last mysql_fetch_field()
//返回用于最后一个mysql_fetch_field()的字段光标的位置。 mysql_free_result()
// Frees memory used by a result set
// /释放一个结果集合使用的内存。
mysql_get_character_set_info()
// Return information about default character set mysql_get_client_info()
// Returns client version information as a string
//返回客户版本信息。 mysql_get_client_version()
// Returns client version information as an integer mysql_get_host_info()
// Returns a string describing the connection
//返回一个描述连接的字符串。 mysql_get_proto_info()
// Returns the protocol version used by the connection
//返回连接使用的协议版本。 mysql_get_server_info()
// Returns the server version number
//返回服务器版本号。 mysql_get_server_version()
// Returns version number of server as an integer mysql_get_ssl_cipher()
// Return current SSL cipher mysql_hex_string()
// Encode string in hexadecimal format mysql_info()
// Returns information about the most recently executed query
//返回关于最近执行得查询的信息。 mysql_init()
// Gets or initializes a MYSQL structure
//获得或初始化一个MYSQL结构。 mysql_insert_id()
// Returns the ID generated for an AUTO_INCREMENT column by the previous query
//返回有前一个查询为一个AUTO_INCREMENT列生成的ID。 mysql_kill()
// Kills a given thread
//杀死一个给定的线程。 mysql_library_end()
// Finalize the MySQL C API library mysql_library_init()
// Initialize the MySQL C API library mysql_list_dbs()
// Returns database names matching a simple regular expression
//返回匹配一个简单的正则表达式的数据库名。 mysql_list_fields()
// Returns field names matching a simple regular expression
//返回匹配一个简单的正则表达式的列名。 mysql_list_processes()
// Returns a list of the current server threads
//返回当前服务器线程的一张表。 mysql_list_tables()
// Returns table names matching a simple regular expression
//返回匹配一个简单的正则表达式的表名。 mysql_load_plugin()
// Load a plugin mysql_load_plugin_v()
// Load a plugin mysql_more_results()
// Checks whether any more results exist mysql_next_result()
//Returns/initiates the next result in multiple-result executions mysql_num_fields()
// Returns the number of columns in a result set
//返回一个结果集合重的列的数量。 mysql_num_rows()
// Returns the number of rows in a result set
//返回一个结果集合中的行的数量。 mysql_options()
// Sets connect options for mysql_real_connect()
//设置对mysql_connect()的连接选项。 mysql_ping() Checks
// whether the connection to the server is working, reconnecting as necessary
//检查对服务器的连接是否正在工作,必要时重新连接。 mysql_plugin_options()
// Set a plugin option mysql_query()
// Executes an SQL query specified as a null-terminated string
//执行指定为一个空结尾的字符串的SQL查询。 mysql_real_connect()
// Connects to a MySQL server
// 连接一个MySQL服务器。 mysql_real_escape_string()
// Escapes special characters in a string for use in an SQL statement, taking into account the current character set of the connection mysql_real_query()
// Executes an SQL query specified as a counted string
//执行指定为带计数的字符串的SQL查询。 mysql_refresh()
// Flush or reset tables and caches mysql_reload()
// Tells the server to reload the grant tables
//告诉服务器重装授权表。 mysql_rollback()
//Rolls back the transaction mysql_row_seek()
// Seeks to a row offset in a result set, using value returned from mysql_row_tell()
//搜索在结果集合中的行,使用从mysql_row_tell()返回的值。 mysql_row_tell()
// Returns the row cursor position
//返回行光标位置。 mysql_select_db()
// Selects a database
//连接一个数据库。 mysql_server_end()
// Finalize the MySQL C API library mysql_server_init()
// Initialize the MySQL C API library mysql_set_character_set()
// Set default character set for current connection mysql_set_local_infile_default()
// Set the LOAD DATA LOCAL INFILE handler callbacks to their default values mysql_set_local_infile_handler()
// Install application-specific LOAD DATA LOCAL INFILE handler callbacks mysql_set_server_option()
// Sets an option for the connection (like multi-statements) mysql_sqlstate()
// Returns the SQLSTATE error code for the last error mysql_shutdown()
// Shuts down the database server
//关掉数据库服务器。 mysql_ssl_set()
// Prepare to establish SSL connection to server mysql_stat()
// Returns the server status as a string
//返回作为字符串的服务器状态。 mysql_store_result()
// Retrieves a complete result set to the client
//检索一个完整的结果集合给客户。 mysql_thread_end()
// Finalize thread handler mysql_thread_id()
// Returns the current thread ID
//返回当前线程的ID。 mysql_thread_init()
// Initialize thread handler mysql_thread_safe()
// Returns 1 if the clients are compiled as thread-safe mysql_use_result()
// Initiates a row-by-row result set retrieval
//初始化一个一行一行地结果集合的检索。 mysql_warning_count()
// Returns the warning count for the previous SQL statement

See

All rights reserved

C 扩展库 - mysql API的更多相关文章

  1. C 扩展库 - mysql API general outline

    Application programs should use this general outline for interacting with MySQL Initialize the MySQL ...

  2. C 扩展库 - mysql API CRUD

    CRUD table create table if not exists `student` ( `id` int auto_increment, `name` varchar(16) not nu ...

  3. C 扩展库 - sqlite3 API

    sqlite3 API Summary sqlite3 The database connection object. Created by sqlite3_open() and destroyed ...

  4. C 扩展库 - sqlite3 API CRUD

    CRUD struct student typedef struct STUDENT { unsigned int id; unsigned char name[16]; unsigned int a ...

  5. PHP基础Mysql扩展库

    mysql扩展库操作步骤如下: 1.连接数据库 2.选择数据库 3.设置操作编码 4.发送指令sql,并返回结果集     ddl:数据定义语句     dml:数据操作语句     dql:数据查询 ...

  6. mysql扩展库-1

    启用mysql扩展库 在php.ini文件中去配置mysql扩展库 extension=php_mysql.dll 可以通过 phpinfo() 查看当前php支持什么扩展库. 在sql扩展库中创建一 ...

  7. php笔记08:数据库编程---使用php的MySQL扩展库操作MySQL数据库

    1.使用php的MySQL扩展库操作MySQL数据库: php有3种方式操作MySQL数据库 (1)mysql扩展库 (2)mysqli扩展库 (3)pdo     mysql扩展库与mysql数据库 ...

  8. mysqli扩展库操作mysql数据库

    配置环境 配置php.ini文件让php支持mysqli扩展库 extension=php_mysqli.dll 建库建表 详见博客 “mysql扩展库操作mysql数据库” 查询数据库 <?p ...

  9. mysql扩展库操作mysql数据库

    环境搭建 启用mysql扩展库,在php.ini文件中去配置mysql扩展库 extension=php_mysql.dll 查询数据库 1.建库建表 //建库testcreate database ...

随机推荐

  1. mysql导入数据load data infile用法(转)

    们常常导入数据!mysql有一个高效导入方法,那就是load data infile 下面来看案例说明 基本语法: load data  [low_priority] [local] infile ' ...

  2. solr分词一:mmseg4j

    刚接触Lucene2.x和Solr2.x的时候,谈到中文分词,会让我立即想到用庖丁中文分词,庖丁中文分词因巨大的中文词库以及支持不限制个数的用户自定义词库,而且是纯文本格式,一行一词,使用后台线程检测 ...

  3. Linux带有时间控制的多进程bash脚本

    目标 以可控制的多进程执行,达到最大执行时长后停止脚本. 思路 1.产生fifo管道,并预填充n个值(与并发数相等) 2.记录脚本本身PID并启动计时器进程(计时终止后杀脚本本身PID) 3.并发执行 ...

  4. GO学习笔记 - 包内首字母大写的名称是被导出的,才能被其它包代码调用!

    在GO语言的任意包内,如果名称的首字母是大写的,意味着这个名称被导出,在其它包中可以使用“包名.名称”方式来调用,如果名称首字母不是大写,那么只能在这个包内部使用!这个概念还真是和以往接触的编程语言的 ...

  5. iOS开发常见无法分类的小问题

    iOS去除api过期警告提示

  6. Hibernate 干货

    一 .hibernate概念: hibernate应用在javaee 三层框架中的dao层(web 层 --service层--dao层),在dao层实现对数据库的CRUD操作.hibernate是对 ...

  7. 【BZOJ2440】[中山市选2011]完全平方数

    题意描述 原题 一句话描述: 求第K个不是完全平方数的倍数的数. K≤$10^{9}$ ------------------------------------------ 题解: 首先,直接求第$k ...

  8. BZOJ 2388--旅行规划(分块&单调栈&二分)

    2388: 旅行规划 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 405  Solved: 118[Submit][Status][Discuss] ...

  9. 看个AV也中招之cve-2010-2553漏洞分析

    试想:某一天,你的基友给你了一个视频文件,号称是陈老师拍的苍老师的老师题材的最新电影.avi,你满心欢喜,在确定文件格式确实为avi格式后,愉快的脱下裤子准备欣赏,打开后却发现什么也没有,而随后你的基 ...

  10. [Objective-C语言教程]内存管理(36)

    内存管理是任何编程语言中最重要的过程之一.它是在需要时分配对象的内存并在不再需要时取消分配的过程. 管理对象内存是一个性能问题; 如果应用程序不释放不需要的对象,则应用程序会因内存占用增加并且性能受损 ...