1 / 25

第 24 章 PHP 与 ODBC 数据源

第三部分 网站设计技术. 第 24 章 PHP 与 ODBC 数据源. 概 述. ODBC 的连结与关闭 ODBC 数据库的 SQL 查询 ODBC 数据库的查询 ODBC 数据库的操作. 1.ODBC. Open Database Connectivity 开放数据库连接 数据源名 Data Source Name DSN. 2. 安装 MYODBC 驱动程序. Open Database Connectivity 开放数据库连接 数据源名 Data Source Name DSN. 2. 3. PHP 语言中对 ODBC 的操作.

cruz-harmon
Download Presentation

第 24 章 PHP 与 ODBC 数据源

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第三部分 网站设计技术 第24章 PHP与ODBC数据源

  2. 概 述 • ODBC的连结与关闭 • ODBC数据库的SQL查询 • ODBC数据库的查询 • ODBC数据库的操作

  3. 1.ODBC • Open Database Connectivity • 开放数据库连接 • 数据源名Data Source Name • DSN

  4. 2.安装MYODBC驱动程序 • Open Database Connectivity • 开放数据库连接 • 数据源名Data Source Name • DSN

  5. 2.

  6. 3. PHP语言中对ODBC的操作 • 建立和数据的连接 • 执行一条SQL语句,或执行查询语句。 • 显示操作结果数据。 • 关闭到数据库的连接

  7. 4.通过ODBC对数据库的连结与关闭 • 非永久性连接: • int odbc_connect(数据源名,用户名,口令,游标类型); • 永久性连接: • int odbc_pconnect(数据源名,用户名,口令,游标类型); • 非永久性连接关闭 • int odbc_close(连接句柄); • int odbc_close_all(void);

  8. 常用的游标类型有: • SQL_CUR_USE_IF_NEEDED • SQL_CUR_USE_ODBC • SQL_CUR_USE_DRIVER • SQL_CUR_DEAFAULT 对某些ODBC驱动程序,执行复杂的存贮过程,有可能会发生类似下面的错误“Cannot open a curor on a stroed procedure that has anything other than a single select statement”,将游标设置为SQL_CUR_USE_ODBC,可以避免这个错误

  9. 4.通过ODBC对数据库的连结与关闭

  10. 5. 通过ODBC的SQL查询 • 格式1:PHP直接向ODBC发送SQL,并立刻执行 • int odbc_do(连接句柄,查询语句); • 或 • int odbc_exec(连接句柄,查询语句); • 格式2:PHP先向ODBC发送SQL,得到命令后再执行 • int odbc_prepare(连接句柄,查询语句); • int odbc_execute(prepare_id,[参数数组]);

  11. 5.

  12. 每次读一条记录 格式:int odbc_fetch_row(int result_id, int[rownumber]) • 从结果集中度去某一个字段的值 格式:int odbc_result(int result_id, mixed field); • 获取查询结果集中的记录数 格式:int odbc_num_rows(int result_id); 6. 通过ODBC获取查询结果

  13. 6. 通过ODBC获取查询结果

  14. 制定序号的记录存于一个数组 格式:int odbc_fetch_into(int result_id, int [rownumber],array result_array); 6. 通过ODBC获取查询结果

  15. 查询结果以表格的形式输出到访问者的浏览器上。int odbc_result_all(int 结果,string [格式]) 6. 通过ODBC获取查询结果

  16. 获取指定字段的字段名称 格式:string odbc_fieldname(int result_id, int field_number); • 获取指定字段的数据类型 格式:string odbc_field_type(int result_id, int field_number); • 获取指定字段的长度 • 格式:string odbc_field_len(int result_id, • int field_number); 6. 通过ODBC获取查询结果

  17. ⒈ 数据返回值的设定 odbc_binmode(int 结果,int 模式) odbc_longreadlen(int 结果,int 长度) ⒉ ODBC的事务处理 odbc_commit(int connection_id); odbc_autocommit(int connection_id,int [OnOff])⒊ 查询设定 odbc_setoption(int 句柄,int 功能,int 选项, int 参数值 ) 7. ODBC的其他操作

  18. 取消操作 格式:int odbc_rollback(int connection_id); • 释放资源 格式:int odbc_free_result(int result_id); int odbc_cursor(int 连接句柄)

  19. 第23章 小结 • ODBC的连结与关闭 • ODBC数据库的SQL查询 • ODBC数据库的查询 • ODBC数据库的操作

  20. 第23章 思考问题 结 束 • 什么是ODBC? • 数据源的含义是什么? • 用户、系统和文件数据源有什么区别? • 在PHP中调用ODBC函数访问MYSQL数据库的一般步骤是什么? • PHP程序向ODBC发送SQL指令有哪两种方式? • 在进行ODBC的连接时,需要指定哪几个参数?

More Related