Search This Blog

28 September 2010

What is short_open_tag?

Well short_open_tag allows you to use <? and <?= in addition to <?php while writing the code. All that you have to do for this setting is

  1. Open your php.ini file
  2. Search for ‘short_open_tag’ directive
  3. The default value of ‘short_open_tag’ directive usually Off, now you can change it to On
  4. Save the php.ini
  5. Restart your PHP stacks to reflect the changes
Now you can write PHP code starts with <? … ?>. This is not recommended but you may need it if don’t want to make changes in your code.

24 September 2010

How to install and configure WAMP Server?

Steps to install and configure WAMP Server are given below,
Installation
  • Download free copy of WAMP Server from http://www.wampserver.com/en/download.php
  • Locate the downloaded file and double click the file to launch the installation.
  • The WAMP Setup Wizard will appear. Click Next.
  • The License Agreement screen will appear - Accept the agreement and click Next.
  • At the Select Destination Location you can change the install directory. The default is C:\wamp. We will use the default directory. Click Next.
  • Select the Start Menu Folder. We will use the default WAMP Server folder. Click Next.
  • You can set WAMP to automatically start each time Windows start. Batter to not check this option because of security issues. You should manually start your WAMP/Apache server when you need it. Click Next.
  • At the Ready to Install screen, click Next.
  • The Installing screen will appear indicating the installation process.
  • You will need to select the default root folder. This is the folder that you store your web site in. The path to the folder is C:\wamp\www. Click OK.
  • In the next step you will select your default web browser. We will have Internet Explorer as the default browser so no changes made to this screen. Click Open.
  • If necessary, check Launch WAMP now and click Finish to complete the Installation.
  • A new icon will appear in the task bar to the left of the clock. When you click the WAMP menu icon a menu will appear.
Configuration
  • To start the server click Start > All Programs > WAMP Server > Start WAMP Server. Then click the WAMP Server icon in the task bar and select Start All Services.
  • If WAMP Server is not getting start, or when you click on WAMP5 Server icon in the task bar and select Localhost, if it show IIS then as IIS and Apache/ WAMP are both web server and might conflict in some way, so you have to disable IIS in order for WAMP to work
    Disabling IIS in Vista/W7: Control Panel > Uninstall Programs > Turn Widows Features On or Off > uncheck Internet Information Services
    Disabling IIS in XP: Control Panel > Add/Remove Programs > Add/Remove Windows Components > uncheckInternet Information Services (IIS)
  •  Restart computer, then restart WAMP

23 September 2010

Writing a recursive query to find out all dates between two given date

--Declaring the required variables
DECLARE @fromdate DATETIME
DECLARE @todate DATETIME
SET @fromdate = '2010-01-01'
SET @todate = '2010-01-10'

--Query to fetch all the dates between two given date
;WITH tmpinfo(tmpdt) AS
(SELECT @fromdate
UNION ALL
SELECT tmpdt + 1
FROM tmpinfo
WHERE tmpdt < @todate)
SELECT * FROM tmpinfo OPTION (MAXRECURSION 0);

Equivalent of Group_Concat function in MS-SQL

--Query to create the table given in the example
CREATE TABLE [dbo].[categoryproductlink](
[categoryproductlinkid] [int] IDENTITY(1,1) NOT NULL,
[categoryid] [int] NOT NULL,
[productid] [int] NOT NULL,
[endeffdt] [smalldatetime] NULL,
CONSTRAINT [PK_categoryproductlink] PRIMARY KEY CLUSTERED
(
[categoryproductlinkid] ASC
)) ON [PRIMARY]

GO
--Query to insert data in above table
SET IDENTITY_INSERT [dbo].[categoryproductlink] ON
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (1, 1, 1, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (2, 1, 2, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (3, 1, 3, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (4, 2, 4, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (5, 2, 5, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (6, 2, 6, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (7, 3, 2, NULL)
INSERT [dbo].[categoryproductlink] ([categoryproductlinkid], [categoryid], [productid], [endeffdt]) VALUES (8, 3, 6, NULL)
SET IDENTITY_INSERT [dbo].[categoryproductlink] OFF

Query 1 – Equivalent to Group_Concate function in MySQL
_________________________________________________________
SELECT CAST(productid AS varchar(20)) + ', ' AS [text()]
FROM categoryproductlink
WHERE categoryid = 2
FOR XML PATH('')
_________________________________________________________

Query 2 – Equivalent to Group_Concate function in MySQL
_________________________________________________________
DECLARE @prodidstr VARCHAR(MAX)

SELECT @prodidstr = COALESCE(@prodidstr+', ','')+CAST(productid AS varchar(8))
FROM categoryproductlink
WHERE categoryid = 2

SELECT @prodidstr
_________________________________________________________

08 September 2010

Query to change collation of a column

ALTER TABLE categorydesc
ALTER COLUMN ldesc text COLLATE SQL_Latin1_General_CP1_CI_AS NULL

Query to fetch description of all tables and columns in current database

SELECT major_id, minor_id, t.name AS [Table Name],
c.name AS [Column Name], value AS [Extended Property]
FROM sys.extended_properties AS ep
INNER JOIN sys.tables AS t ON ep.major_id = t.object_id
INNER JOIN sys.columns AS c ON ep.major_id = c.object_id
AND ep.minor_id = c.column_id
WHERE class = 1
ORDER BY t.name, c.name

Query to get Collation of database and columns of a table

To get dafault collation of database
1 - SELECT DATABASEPROPERTYEX('GoldenTours', 'Collation')
2 - SELECT collation_name FROM sys.databases WHERE name = 'GoldenTours'

Query to get Collation of all the columns of a table
SELECT name, collation_name
FROM sys.columns
WHERE OBJECT_ID IN ( SELECT OBJECT_ID FROM sys.objects
WHERE type = 'U'
AND name = 'categorydesc')