MySQL vs MySQLi vs PDO

For PHP5;

  • mysql: Deprecated

For PHP7:

  • mysql: N/A
  • mysqli: Deprecated
Advertisements

Inno Setup Launch Application

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

If application requires admin privileges:

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent runascurrentuser

IO handler is not valid error in Delphi

Indy Tidhttp component complains “IO handler is not valid” when the original URL redirects to a HTTPS url.

Solution: Use a TIdSSLIOHandlerSocketOpenSSL

uses IdSSLOpenSSL

Also copy SSL DLL (libeay32.dll, ssleay32.dll)

var
  Http: TIdHTTP;
  MS: TMemoryStream;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
  Http := TIdHTTP.Create(nil);
  Http.HandleRedirects:=True;
  try
    MS := TMemoryStream.Create;
    LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    try
      Http.IOHandler:=LHandler;
      Http.OnWork:= HttpWork;
      Http.OnRedirect:= HttpRedirect;
//    Http.RedirectMaximum:=9;
      Http.Get(urlfile, MS);
      MS.SaveToFile(filename);
    finally
      MS.Free;
      LHandler.Free;
    end;
  finally
    Http.Free;
  end;
end;

 

Get User IP using PHP

 $client  = $_SERVER['HTTP_CLIENT_IP'];
 $forward = $_SERVER['HTTP_X_FORWARDED_FOR'];
 $remote  = $_SERVER['REMOTE_ADDR'];

What is the difference between HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR? – it is impossible to say. Different proxies may implement these, or may not. The implementations may vary from one proxy to the next, and they may not. A lack of a standard breeds question marks.
If more than one proxy was involved – the X-Forwarded-For: header might then contain a complete track of the forwarding chain, whereas the Client-IP: header would contain the actual client IP. This is pure speculation, however.

BeginUpdate and EndUpdate in Delphi

If you use a Delphi component like a ListBox, Memo, TreeList, ListView,… and you add or modify a lot of items (lines, nodes,…), the component’s performance becomes very slow. This is due to the fact that after each change, it is redrawn on the screen. Solution:

 

 ListBox1.Items.BeginUpdate;
 for i := 1 to 10000 do
 ListBox1.Items.Add('abcd');
 ListBox1.Items.EndUpdate;

Export Registry Key in Delphi

var
 R: TRegistry;
 ErrorCode: Integer;
begin
 NTSetPrivilege('SeBackupPrivilege', true);
 R:= TRegistry.Create;
 try
 R.RootKey := HKEY_LOCAL_MACHINE;
 if R.OpenKeyReadOnly('\Software\My Key') then
 begin
 ErrorCode := RegSaveKey(R.CurrentKey, 'export.reg'), nil);
 R.CloseKey;
 if ErrorCode <> ERROR_SUCCESS then
 raise Exception.CreateFmt('Error Code: %u', [ErrorCode]);
 end
 else
 raise Exception.Create('Key does not exist');
 finally
 R.Free;
 end;
end;