使用mysqlhelper可以连接mysql
已经验证OK通过。
参考地址:
https://www.oschina.net/code/snippet_579976_48967 https://files.cnblogs.com/files/mobilecard/MySQLHelper.rar 这是一个操作MySQL的类,该类必须和libmysql.dll,dbxmys.dll两个文件一起使用.
安装:
将dll拷贝到C:\Windows\System32下和项目目录下,发行的时候放到exe目录下即可.
使用:
//使用insert,update,delete语句时请使用:TMySQLHelper.ExecSQL();返回受影响行数Integer;
//使用select语句时请使用TMySQLHelper.Query();返回数据集TSQLQuery;
测试:
WIN7 SP1 X86 , MySQL 5.5.51 , Delphi XE7 测试通过.
{*
* MySQL Helper v1.
* 2015.6.
* 说明:
* 这是一个操作MySQL的类,该类必须和libmysql.dll,dbxmys.dll两个文件一起使用.
* 安装:
* 将dll拷贝到C:\Windows\System32下和项目目录下,发行的时候放到exe目录下即可.
* 使用:
* //使用insert,update,delete语句时请使用:TMySQLHelper.ExecSQL();返回受影响行数Integer;
* //使用select语句时请使用TMySQLHelper.Query();返回数据集TSQLQuery;
* 测试:
* WIN7 SP1 X86 , MySQL 5.6. , Delphi XE7 测试通过.
* ==========================================
* var
* MySQLHelper : TMySQLHelper;
* begin
* MySQLHelper := TMySQLHelper.Create;
* MySQLHelper.User_name := 'root';
* MySQLHelper.Password := 'root';
* MySQLHelper.Database := 'Test';
* ShowMessage('影响行数:'+IntToStr(MySQLHelper.ExecSQL('INSERT INTO test(name)values(''FangJun'')')));
* MySQLHelper.Free;
* end;
* ==========================================
* var
* MySQLHelper : TMySQLHelper;
* SQLQuery : TSQLQuery;
* begin
* MySQLHelper := TMySQLHelper.Create;
* MySQLHelper.User_name := 'root';
* MySQLHelper.Password := 'root';
* MySQLHelper.Database := 'Test';
* SQLQuery := TSQLQuery.Create(nil);
* SQLQuery := MySQLHelper.Query('select * from test');
* while not SQLQuery.Eof do
* begin
* ShowMessage('姓名:'+VarToStr(SQLQuery.FieldValues['name']);
* SQLQuery.Next;
* end;
* MySQLHelper.MySQLClose;
* MySQLHelper.Free;
* end;
* ==========================================
}
unit MySQLHelper;
interface
uses
SysUtils,StdCtrls,Classes,Variants,DB,SqlExpr,DBXMySQL;
type
TMySQLHelper = class(TObject)
private
_PORT : Integer;
_HOST : string;
_DATABASE : string;
_USER_NAME : string;
_PASSWORD : string;
_SERVERCHARSET : string;
_SQLQuery : TSQLQuery;
_SQLConnection : TSQLConnection;
procedure Set_PORT(const Value: Integer);
procedure Set_HOST(const Value: string);
procedure Set_DATABASE (const Value: string);
procedure Set_USER_NAME(const Value: string);
procedure Set_PASSWORD (const Value: string);
procedure Set_SERVERCHARSET(const Value: string);
function MySQLConnection:TSQLConnection;
public
constructor Create; overload;
property Post:Integer write Set_PORT;
property Host:string write Set_HOST;
property Database:string write Set_DATABASE;
property User_name:string write Set_USER_NAME;
property Password:string write Set_PASSWORD;
property ServerCharSet:string write Set_SERVERCHARSET;
function ExecSQL(const SQL:string):Integer;
function Query(const SQL:string):TSQLQuery;
procedure MySQLClose;
end;
implementation
//初始化
constructor TMySQLHelper.Create;
begin
_HOST := '192.168.1.222';
_PORT := ;
_SERVERCHARSET := 'utf8';
end;
//执行 SQL 语句 INSERT , UPDATE , DELETE 返回影响行数
function TMySQLHelper.ExecSQL(const SQL:string):Integer;
begin
if not Assigned(_SQLQuery) then
_SQLQuery := TSQLQuery.Create(nil);
with _SQLQuery do
begin
Close;
SQL.Clear;
SQLConnection := MySQLConnection;
end;
try
_SQLQuery.SQL.Add(SQL);
result := _SQLQuery.ExecSQL;
except on E: Exception do
raise Exception.Create('SQL语句执行失败 :'+E.Message);
end;
MySQLClose;
end;
//执行 SQL 语句 Select 返回 数据集
function TMySQLHelper.Query(const SQL:string):TSQLQuery;
begin
if not Assigned(_SQLQuery) then
_SQLQuery := TSQLQuery.Create(nil);
with _SQLQuery do
begin
Close;
SQL.Clear;
SQLConnection := MySQLConnection;
end;
try
_SQLQuery.SQL.Add(SQL);
_SQLQuery.Open;
_SQLQuery.Active := true;
result := _SQLQuery;
except on E: Exception do
raise Exception.Create('SQL语句查询失败 :'+E.Message);
end;
end;
//关闭连接
procedure TMySQLHelper.MySQLClose;
begin
_SQLQuery.Close;
_SQLConnection.Close;
end;
//连接MySQL 返回 TSQLConnection
function TMySQLHelper.MySQLConnection:TSQLConnection;
begin
if not Assigned(_SQLConnection) then
_SQLConnection := TSQLConnection.Create(nil);
with _SQLConnection do
begin
Close;
GetDriverFunc := 'getSQLDriverMYSQL';
LibraryName := 'dbxmys.dll';
VendorLib := 'LIBMYSQL.dll';
DriverName:= 'MySQL';
Params.Values['drivername']:= 'MySQL';
Params.Values['port'] := IntToStr(_PORT);
Params.Values['hostname'] := _HOST;
Params.Values['database'] := _DATABASE;
Params.Values['user_name'] := _USER_NAME;
Params.Values['password'] := _PASSWORD;
Params.Values['ServerCharSet'] := _SERVERCHARSET;
end;
try
_SQLConnection.Open;
_SQLConnection.Connected := true;
result := _SQLConnection;
except on E: Exception do
raise Exception.Create('数据库连接错误:'+E.Message);
end;
end;
procedure TMySQLHelper.Set_PORT(const Value: Integer);
begin
if Value<> then
_PORT := Value
end;
procedure TMySQLHelper.Set_HOST (const Value: string);
begin
if Value<>'' then
_HOST := Value
end;
procedure TMySQLHelper.Set_DATABASE (const Value: string);
begin
_DATABASE := Value
end;
procedure TMySQLHelper.Set_USER_NAME (const Value: string);
begin
_USER_NAME := Value;
end;
procedure TMySQLHelper.Set_PASSWORD (const Value: string);
begin
_PASSWORD := Value;
end;
procedure TMySQLHelper.Set_SERVERCHARSET (const Value: string);
begin
if Value<>'' then
_SERVERCHARSET := Value
end;
end.
使用mysqlhelper可以连接mysql的更多相关文章
- C#连接Mysql数据库 MysqlHelper.cs文件
mysql.data.dll下载_c#连接mysql必要插件mysql.data.dll是C#操作MYSQL的驱动文件,是c#连接mysql必要插件,使c#语言更简洁的操作mysql数据库.当你的电脑 ...
- .NET连接MySQL数据库的方法实现
突然对.NET连接MySQL数据库有点兴趣,于是乎网上到处找资料,学习MySQL的安装,MySQL的使用等等等等,终于搞定了! 最终效果就是显示数据库中数据表的数据: 首先,当然要有MySQL数据库啦 ...
- .net连接MySQL的方法
摘自:http://www.cnblogs.com/huayangmeng/archive/2011/04/06/2006866.html 最近要用C#做一个东西,连接之前项目的数据库(用MySQL建 ...
- nodejs进阶(6)—连接MySQL数据库
1. 建库连库 连接MySQL数据库需要安装支持 npm install mysql 我们需要提前安装按mysql sever端 建一个数据库mydb1 mysql> CREATE DATABA ...
- 【初学python】使用python连接mysql数据查询结果并显示
因为测试工作经常需要与后台数据库进行数据比较和统计,所以采用python编写连接数据库脚本方便测试,提高工作效率,脚本如下(python连接mysql需要引入第三方库MySQLdb,百度下载安装) # ...
- Node.js Express连接mysql完整的登陆注册系统(windows)
windows学习环境: node 版本: v0.10.35 express版本:4.10.0 mysql版本:5.6.21-log 第一部分:安装node .Express(win8系统 需要&qu ...
- PDO连接mysql数据库
1.PDO简介 PDO(PHP Data Object) 是PHP 5 中加入的东西,是PHP 5新加入的一个重大功能,因为在PHP 5以前的php4/php3都是一堆的数据库扩展来跟各个数据库的连接 ...
- 使用ABP EntityFramework连接MySQL数据库
ASP.NET Boilerplate(简称ABP)是在.Net平台下一个很流行的DDD框架,该框架已经为我们提供了大量的函数,非常方便与搭建企业应用. 关于这个框架的介绍我就不多说,有兴趣的可以参见 ...
- jmeter之连接mysql和SQL Server配置
下载jdbc驱动 在使用jmeter做性能或自动化测试的时候,往往需要直接对数据库施加压力,或者某些参数只能从数据库获取,这时候就必须使用jmeter连接数据库. 1.下载对应的驱动包 mysql驱动 ...
随机推荐
- [Swift]LeetCode280. 摆动排序 $ Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] < ...
- [Swift]LeetCode840. 矩阵中的幻方 | Magic Squares In Grid
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, co ...
- python之定义参数模块argparse(一)基本使用
在shell脚本中,若脚本带参数,则在脚本中使用$1.$2...等引用, 在python中,也可以定义类似的引用参数,可以为必选项也可以可选项. 基本用法如下三种: 1.必选项(位置参数) impor ...
- python获取当前运行程序的名字
import os filename = os.path.abspath(__file__) print filename 打印结果: E:\bluedon\test.py
- CDN边缘节点容器调度实践(下)
5月27日,OSC 源创会在上海成功举办.又拍云系统开发高级工程师黄励博在大会分享了<CDN 边缘节点容器调度的实践>.主要介绍又拍云自主开发的边缘节点容器调度方案,从 0 到 1 ,实现 ...
- 并发编程(七)——AbstractQueuedSynchronizer 之 CountDownLatch、CyclicBarrier、Semaphore 源码分析
这篇,我们的关注点是 AQS 最后的部分,共享模式的使用.本文先用 CountDownLatch 将共享模式说清楚,然后顺着把其他 AQS 相关的类 CyclicBarrier.Semaphore 的 ...
- SpringBoot是如何动起来的
SpringBoot是如何动起来的 程序入口 SpringApplication.run(BeautyApplication.class, args); 执行此方法来加载整个SpringBoot的环境 ...
- Spring Cloud Eureka基本概述
记一次Eureka的进一步学习. 一.Eureka简介 百科描述:Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡 ...
- 你以为的MongoDB副本集的高可用是真的高可用了吗?
很久没来更新博客,自感是一个只会搬砖的劳工,总搞些MySQL相关的数据库实在无聊,且时不时遇到些不讲道理的Dev吧,真的是心累至极,有种想回头我也去干开发的冲动,当个需求者有话语权要风得风,要雨得雨多 ...
- LeetCode专题-Python实现之第1题:Two Sum
导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...