转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> MySql >> 正文
MySQL数据库学习笔记(二)         ★★★★

MySQL数据库学习笔记(二)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2752 更新时间:2009/4/22 20:49:06

1.1.C API

    MySQL随安装包提供用C编程语言编写的客户机库,可以用它编写访问MySQL的客户机程序。这个库定义了应用程序编程接口,包括下面的实用程序:

1.         建立和终止与服务器会话的连接管理例程。

2.         构造查询的例程,将例程发送到服务器,并处理结果。

3.         当其他C API调用失败时,确定错误准确原因的状态和错误报告函数。
实际在使用编程测试中发现,网上下载的4.1.1a-alpha版本动态库中没有进行动态语句处理的函数,下载MySQL5.0的版本用5.0的动态库覆盖4.1的动态库,测试代码运行成功。测试代码见附录一。

1.1.1. 如何执行数据定义语句

可以使用mysql_query或者mysql_real_query函数来实现。

例如:

mysql_query(mysql, "DROP TABLE IF EXISTS test_table")

mysql_query(mysql, "CREATE TABLE test_table(col1 INT,\

                     col2 VARCHAR(40),\

                     col3 SMALLINT,\

                     col4 TIMESTAMP)"

其中mysqlMYSQL类型的指针。范例程序参见附录一。

1.1.2. 如何执行数据操作语句

可以使用mysql_preparemysql_param_count函数来实现。

例如:

char INSERT_SAMPLE []="INSERT INTO test_table(col1,col2,col3) VALUES(?,?,?)"

MYSQL_STMT *stmt= mysql_prepare(mysql, INSERT_SAMPLE, strlen(INSERT_SAMPLE));

/* Get the parameter count from the statement */

       param_count= mysql_param_count(stmt);

范例程序参见附录一。

1.1.3. 如何执行数据库动态操作

可以使用如下函数来实现。

 C API Prepared Statement Function Descriptions.

Function

Description

mysql_prepare()

Prepares an SQL string for execution.

mysql_param_count()

Returns the number of parameters in a prepared SQL statement.

mysql_get_metadata()

Returns prepared statement metadata in the form of a result set.

mysql_bind_param()

Associates application data buffers with the parameter markers in a prepared SQL statement.

mysql_execute()

Executes the prepared statement.

mysql_stmt_affected_rows()

Returns the number of rows changes, deleted, or inserted by the last UPDATE, DELETE, or INSERT query.

mysql_bind_result()

Associates application data buffers with columns in the result set.

mysql_stmt_store_result()

Retrieves the complete result set to the client.

mysql_stmt_data_seek()

Seeks to an arbitrary row number in a statement result set.

mysql_stmt_row_seek()

Seeks to a row offset in a statement result set, using value returned from mysql_stmt_row_tell().

mysql_stmt_row_tell()

Returns the statement row cursor position.

mysql_stmt_num_rows()

Returns total rows from the statement buffered result set.

mysql_fetch()

Fetches the next row of data from the result set and returns data for all bound columns.

mysql_stmt_close()

Frees memory used by prepared statement.

mysql_stmt_errno()

Returns the error number for the last statement execution.

mysql_stmt_error()

Returns the error message for the last statement execution.

mysql_stmt_sqlstate()

Returns the SQLSTATE error code for the last statement execution.

mysql_send_long_data()

Sends long data in chunks to server.

范例程序参见附录一。

1.1.4. 性能测试

测试环境P4 1.8G/512M联想电脑,windowns2000系统,VC6。利用MySQL C API采用预处理mysq_prepare()进行SQL语句操作,模拟网管agt产生moinfo信息文件过程。Moinfo表定义如下:

CREATE TABLE moinfo (

  instanceid int(10) unsigned NOT NULL d

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


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台