DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: 2ccc_mis
今日帖子: 8
在线用户: 15
导航: 论坛 -> 移动应用开发 斑竹:flyers,iamdream  
作者:
男 chujoy (Allenchu) ★☆☆☆☆ -
普通会员
2009/12/3 19:19:01
标题:
 如何用DELPHI远程连接MYSQL?谁能帮我修改下? 浏览:1251
加入我的收藏
楼主: 比如我服务器是

IP:192.168.0.2

数据库名为:sq_chujoy

数据库用户名为:sq_chujoy

数据库密码为:123456

数据库表名为:cdb_members

论坛用户名为:admin

论坛密码为:12456

下面代码应该怎么改啊~??用于登陆论坛成功后用弹出对话框用的~



 unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DBXpress, DB, SqlExpr, FMTBcd, Grids, IdHashMessageDigest,
  IdGlobal, IdHash;

type
  TForm1 = class(TForm)
    Button1: TButton;
    SQLQuery1: TSQLQuery;
    SQLConnection1: TSQLConnection;
    Label1: TLabel;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Connection: TSQLConnection;

implementation

uses md5;

//uses mysql;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  {SQLConnection1 := TSQLConnection.Create(nil);
  SQLConnection1.DriverName := 'dbxmysql';
  SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50';
  SQLConnection1.LibraryName := 'dbxopenmysql50.dll';
  SQLConnection1.VendorLib := 'libmysql.dll';
  SQLConnection1.LoginPrompt := false;}
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  user, pwd: string;
  MyMD5: TIdHashMessageDigest5;
  Digest: T4x4LongWordRecord;
  //i,j:integer;
begin
  user := Edit1.Text;
  pwd := Edit2.Text;
  {md5密码}
  MyMD5 := TIdHashMessageDigest5.Create;
  Digest := MyMD5.HashValue(pwd);
  pwd := MyMD5.AsHex(Digest);
  {md5密码}
  SQLConnection1.Params.Append('Database=');
  SQLConnection1.Params.Append('User_Name=');
  SQLConnection1.Params.Append('Password=');
  SQLConnection1.Params.Append('HostName=');
  SQLConnection1.Open;
  if SQLConnection1.Connected = true then
    Label1.Caption := 'success'
  else
    Label1.Caption := 'fail';
  SQLQuery1.Close;
  SQLQuery1.SQL.Clear;
  SQLQuery1.SQL.add('SET NAMES GBK');
  SQLQuery1.ExecSQL;
  SQLQuery1.SQL.Clear;
  SQLQuery1.SQL.Add('SELECT * from xyxusers where username=:username and userpwd=:pwd');
  SQLQuery1.Params.ParamByName('username').Value := user;
  SQLQuery1.Params.ParamByName('pwd').Value := pwd;
  SQLQuery1.Active := true;
  if not SQLQuery1.IsEmpty then
  begin
    ShowMessage('登陆成功');
  end
  else
    ShowMessage('登陆失败');
  // i := 0;
   {SQLQuery1.First;
   while not SQLQuery1.eof do
   begin

     for j := 0 to SQLQuery1.FieldCount - 1 do
       StringGrid1.cells[j + 1, i + 1] := SQLQuery1.Fields[j].AsString;
     Memo1.Lines.Add(SQLQuery1.FieldValues['card']);
     SQLQuery1.next;
     inc(i);
   end;}
  SQLQuery1.Active := false;
  SQLConnection1.Close;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if SQLConnection1.Connected = true then
    SQLConnection1.Close;
  SQLConnection1.Free;
end;

end.
----------------------------------------------
我只爱你7777777
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行2238.281毫秒 RSS