Tuesday, May 15, 2012

[php] Auto include .php files

Below code to enable auto include for php files. Change the zinclude.php to your current php file name.

$incPath=str_replace("zinclude.php", "", __FILE__);
foreach (glob($incPath."*.php") as $filename){
  $filename=str_replace($incPath, "", $filename);
  //echo$filename."
";//enable for debuging
  if($filename<>"zinclude.php"){
    require_once $filename;
  }
}

Thursday, November 17, 2011

[MSSQL] Copy & Delete File on Server Side

sp_configure 'xp_cmdshell', '1'
go
reconfigure

exec master.dbo.xp_cmdshell 'copy drive:\folder\filename.ext drive:\folder\filename.ext'

exec master.dbo.xp_cmdshell 'del drive:\folder\fiilename.ext'

Tested on MSSQL 2005

Reference:
http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-tools/4237/Script-to-delete-backup-files-which-are-7-days-old
http://www.mssqltips.com/sqlservertip/1020/enabling-xpcmdshell-in-sql-server-2005/

[MSSQL] Import Excel Using Query


Below example how to import row data directly using queries. 
 
SELECT * INTO XLImport5 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', 'SELECT * FROM [Customers$]')

Tested on MSSQL 2005.
 
Reference: http://support.microsoft.com/kb/321686

Monday, November 14, 2011

[MSSQL] Export to Excel using query

Below example how to export row data directly using queries.

1. Enable Ad Hoc Distributed Queries.
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO


2. Create new excel sheet and define the columns names exactly the same as the select statements below.

Then
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\contact.xls;', 'SELECT * FROM [Sheet1$]')
SELECT TOP 5 FirstName, LastName
FROM Person.Contact


Tested on MSSQL 2005.

Resource: http://blog.sqlauthority.com/2008/01/08/sql-server-2005-export-data-from-sql-server-2005-to-microsoft-excel-datasheet/

Wednesday, January 19, 2011

Saturday, October 9, 2010

[MSDOS] FTP Upload

Below sample how we can implement ftp by using Dos.

ftpbackup.bat
--------------
echo off
echo %date%
SET aa=%date:~7,2%
echo %aa%
ftp -s:ftp%aa%.txt

ftp01.txt
---------
open [ip address]
[username]
[password]
cd /ddrive/autobackup
binary
put file01.zip
quit

Then we can put this into scheduler thus we will have auto ftp processes the way we wanted.

Monday, September 27, 2010

[.NET] Installation Notes

When installing any .NET Framework if an error occurred then try to turn off the ISS then redo the installation.