Database Blog

April 20, 2007

PHP, SQL Server with IIS

Filed under: Wamp — johnjacob @ 10:29 PM

Installing & Configuring PHP with IIS

Download the Windows binary of PHP 5 from php.net. Unzip it to, say, C:\PHP. Open the “php.ini-dist” in C:\PHP and save it as “php.ini”. Locate the following line in php.ini:                         ; cgi.force_redirect = 1

We need to uncomment this line and change the setting to ‘0’ to run PHP under IIS, as shown below:

cgi.force_redirect = 0

Click Start -> Control Panel -> Administrative Tools -> Internet Information Services:

iis1.jpg

Select Default Web Site, right-click on it and select Properties:

iis2.jpg

Select the Home Directory tab and click on Configuration. In the Application Configuration window, select Mappings and click on the add button.

iis3.jpg

Enter the executable as C:\PHP\PHP-CGI.EXE and the extension as .php, as shown below.  

iis4.jpg

Click on OK button. This configuration enables IIS to run PHP files using PHP interpreter.  Finally, right-click on My Computer, select Properties, select Advanced tab and click on Environment Variables. In System Variables, select Path and click on Edit button. Add these paths to the variable value:                        C:\PHP;C:\PHP\EXT

Click OK to finish.

iis5.jpg

 

Configuring PHP with SQL Server  PHP supports SQL Server with a set of mssql_xxx functions. The PHP extension directory (normally \PHP\EXT) contains all the database libraries, like php_mssql.dll for SQL Server. Open php.ini. Verify that the “extension_dir=” points to the folder in which the database libraries are stored, as shown below:extension_dir = “c:\php\ext”

Next, look for the line “;extension=php_mssql.dll” in php.ini. Uncomment this line. It tells PHP to load the php_mssql.dll extension library into memory, which makes the mssql_xxx set of functions available to us.  You need the SQL client tools installed on the Web Server. The minimum requirement is the file “ntwdblib.dll”, which can be located in the \Windows\System32 folder on your SQL Server. Copy it to \Windows\System32 folder on your Web Server.  Now restart your web server, IIS. Create a file called “test.php” in notepad and enter the following:$server=”Beta”;$username=”sa”;$password=”";$sqlconnect=mssql_connect($server, $username, $password);$sqldb=mssql_select_db(“opus”,$sqlconnect);$sqlquery=”SELECT order_no FROM Orderlines;”;$results= mssql_query($sqlquery);while ($row=mssql_fetch_array($results)){echo $row['order_no'].”<br>\n”;}mssql_close($sqlconnect); 

Save the file in the web server folder “c:\Inetpub\wwwroot”. Open Internet Explorer and type the URL:           

http://alpha/test.php

Here Alpha is the Web Server and Beta is the Database Server. The above URL returns the query results on the browser. It is possible to execute SQL statements as well as Stored Procedures of SQL Server in a similar manner. 

Installation and Configuration

Filed under: Wamp — johnjacob @ 8:59 PM

You have Windows XP or Vista. Download the other packages from their respectives sites:

  1. Apache from httpd.apache.org
  2. MySQL from www.mysql.com
  3. PHP from www.php.net

Download the latest stable versions. In this section, we are using Apache 2.0.55, MySQL 5.0.18 and PHP 5.1.5.

After installing Apache, you may see the files in the folder C:\Program Files\Apache Group\Apache2\. The web pages are stored in “htdocs” sub-folder and the configuration files are stored in “conf” sub-folder. You may save your web pages in a new folder “c:\htdocs”. In this case you need to modify the “httpd” file in “conf” folder to make these changes:

DocumentRoot “C:/htdocs”

<Directory “C:/htdocs”>

Open a browser and type

http://localhost

If the Apache is installed properly, you will see a screen as shown below:

There are two main ways to install PHP for Windows: either manually or by using the installer. Once you have PHP installed on your Windows system, you may also want to load various extensions for added functionality.

Try the PHP 5.1.5 installer downloaded. It will install PHP into C:\PHP. You may see a screen to choose the Server Type from a number of options, which include web servers like PWS, IIS, Apache and Xitami.

php11.jpg

Unfortunately, I was asked to configure the web server manually, when opted for Apache. Let us do that!

Unzip the downloaded PHP 5.1.5 zip file into the C:\PHP folder. Open the file “php.ini-recommended” and save it as “php.ini” to your Windows folder (e.g., C:\Windows). Copy “php5ts.dll” to any path mentioned in PATH environment variable (e.g., C:\Windows\System32).

At his point of time, Apache does not recognize PHP pages. If you load the test page now in your browser, you will get a screen similar to the following, since Apache does not get the help of PHP to interpret the page:

 test2.jpg

Now modify Apache configuration file httpd to reflect the following lines:

 LoadModule php5_module “c:/php/php5apache2.dll”

AddType application/x-httpd-php .php

Restart Apache web server. Test the page “test.php” with your browser. If the installations are correct, you may get a screen similar to the following:

php3.jpg 

Scroll down the page. There is much information available on the PHP setup on Apache. Note that we have now a database engine called “sqlite” as part of the PHP.

Next install the full fledged database MySQL 5.0.18. The installation will complete the service configuration as well, so that Windows will start MySQL as a service. Once the installation is over, you may try the command line client. It will appear as shown below:

 mysql.jpg

Again, configure PHP to talk to MySQL. Open php.ini (in C:\WINDOWS) and make the following modifications:

1. Find “extension_dir” and modify it to show the directory in which the loadable extensions (modules) reside.

extension_dir = “c:\php\ext”

2. Locate Windows extensions and uncomment the line which reads:

                        Extension = php_mysql.dll

3. In order to use PHP’s session functions, you need to modify session save path as shown here:

session.save_path = “c:\windows\temp”

Finally, add C:\PHP as a path in Windows system environment variable PATH. Otherwise, while Apache tries to load php-mysql.dll, it may show an error warning like this:

“PHP Startup: Unable to load dynamic library ‘php_mysql.dll’ –

The specified module could not be found.”

If everything is done right, if you again test the page “test.php” in your browser, you will see screens with MySQL variables defined as shown below:

mysql2.jpg

mysql3.jpg

April 19, 2007

US State Abbreviations

Filed under: Travelogue — johnjacob @ 7:55 PM

US States, Abbreviations and Capitals
State Standard
Abbreviation
Postal
Abbreviation
Capital City
Alabama Ala. AL Montgomery
Alaska Alaska AK Juneau
Arizona Ariz. AZ Phoenix
Arkansas Ark. AR Little Rock
California Calif. CA Sacramento
Colorado Colo. CO Denver
Connecticut Conn. CT Hartford
Delaware Del. DE Dover
Florida Fla. FL Tallahassee
Georgia Ga. GA Atlanta
Hawaii Hawaii HI Honolulu
Idaho Idaho ID Boise
Illinois Ill. IL Springfield
Indiana Ind. IN Indianapolis
Iowa Iowa IA Des Moines
Kansas Kans. KS Topeka
Kentucky Ky. KY Frankfort
Louisiana La. LA Baton Rouge
Maine Maine ME Augusta
Maryland Md. MD Annapolis
Massachusetts Mass. MA Boston
Michigan Mich. MI Lansing
Minnesota Minn. MN St. Paul
Mississippi Miss. MS Jackson
Missouri Mo. MO Jefferson City
Montana Mont. MT Helena
Nebraska Nebr. NE Lincoln
Nevada Nev. NV Carson City
New Hampshire N.H. NH Concord
New Jersey N.J. NJ Trenton
New Mexico N.M. NM Santa Fe
New York N.Y. NY Albany
North Carolina N.C. NC Raleigh
North Dakota N.D. ND Bismarck
Ohio Ohio OH Columbus
Oklahoma Okla. OK Oklahoma City
Oregon Ore. OR Salem
Pennsylvania Pa. PA Harrisburg
Rhode Island R.I. RI Providence
South Carolina S.C. SC Columbia
South Dakota S.D. SD Pierre
Tennessee Tenn. TN Nashville
Texas Tex. TX Austin
Utah Utah UT Salt Lake City
Vermont Vt. VT Montpelier
Virginia Va. VA Richmond
Washington Wash. WA Olympia
West Virginia W.Va. WV Charleston
Wisconsin Wis. WI Madison
Wyoming Wyo. WY Cheyenne

Paritioning in SQL Server 2005

Filed under: Microsoft SQL Server — johnjacob @ 6:35 PM

On Partioning tables in SQL Server 2005, here is a good article.

Some photos of Columbus, OH

Filed under: Travelogue — johnjacob @ 5:25 PM

dublinoh-180.jpgdublinoh-188.jpg
dublinoh-184.jpgdublinoh-179.jpg
dublinoh-176.jpgdublinoh-175.jpg
dublinoh-174.jpgdublinoh-172.jpg

April 16, 2007

Bookmarks for Oracle

Filed under: Oracle — johnjacob @ 9:46 PM

Bookmarks for MySQL

Filed under: MySQL — johnjacob @ 8:25 PM

April 13, 2007

Data Partitioning in SQL Server 2000

Filed under: Microsoft SQL Server — johnjacob @ 3:02 PM

There are two types of data partitioning: horizontal partitioning and vertical partitioning. In Horizontal Partitioning, a table is split horizontally with a subset of rows to form another similar table with the same number of columns. The structure of the table will remain the same. In Vertical Partitioning, a table with a large number of columns or very large columns is split into multiple partitions, each with the same number of rows but less number of columns. 

Here I am discussing the Horizontal Partitioning. We have a large table ORDERLINES with columns such as ORDER_NO, LINE_NO, CROSS_REF, USED_BUT_NOT_PRICED, LOST, and ORIG_COMM. Let us first partition ORDERLINES into four different tables. The data is divided with the following criteria:


1.       ORDER_NO <= ‘1020000′
2.       ORDER_NO BETWEEN ‘1020000′ AND ‘1040000′
3.       ORDER_NO BETWEEN ‘1040000′ AND ‘1060000′
4.       ORDER_NO >= ‘1060000′ 

Given below are the steps involved in this process: 

I. Create 4 tables with the same structure as that of ORDERLINES 

1. CREATE TABLE [dbo].[ORDERLINES01] (
[OLID] [int],
[ORDER_NO] [nchar] (15) NOT NULL ,
[LINE_NO] [int] NOT NULL ,
[LOST] [bit] NULL ,
[ORIG_COMM] [numeric](5, 2) NULL
) ON [PRIMARY]

2. CREATE TABLE [dbo].[ORDERLINES02] (
[OLID] [int],
[ORDER_NO] [nchar] (15) NOT NULL ,
[LINE_NO] [int] NOT NULL ,
[LOST] [bit] NULL ,
[ORIG_COMM] [numeric](5, 2) NULL
) ON [PRIMARY]

3. CREATE TABLE [dbo].[ORDERLINES03] (
[OLID] [int],
[ORDER_NO] [nchar] (15) NOT NULL ,
[LINE_NO] [int] NOT NULL ,
[LOST] [bit] NULL ,
[ORIG_COMM] [numeric](5, 2) NULL
) ON [PRIMARY]

4. CREATE TABLE [dbo].[ORDERLINES04] (
[OLID] [int],
[ORDER_NO] [nchar] (15) NOT NULL ,
[LINE_NO] [int] NOT NULL ,
[LOST] [bit] NULL ,
[ORIG_COMM] [numeric](5, 2) NULL
) ON [PRIMARY]

II. Insert data into these four tables  


1. INSERT INTO ORDERLINES01 ([ORDER_NO], [LINE_NO],
 [CROSS_REF], [SED_BUT_NOT_PRICED], [LOST], [ORIG_COMM])
 SELECT *
 FROM ORDERLINES
 WHERE (ORDER_NO <= '1020000')
     GO
     UPDATE ORDERLINES01
     SET OLID = '1'
     GO

2. INSERT INTO ORDERLINES02 ([ORDER_NO], [LINE_NO],
 [CROSS_REF], [USED_BUT_NOT_PRICED], [LOST], [ORIG_COMM])
 SELECT *
 FROM ORDERLINES
 WHERE (ORDER_NO BETWEEN '1020000' AND '1040000')
 GO
 UPDATE ORDERLINES02
 SET OLID = '2'
 GO

3. INSERT INTO ORDERLINES03 ([ORDER_NO], [LINE_NO],
 [CROSS_REF], [USED_BUT_NOT_PRICED], [LOST], [ORIG_COMM])
 SELECT *
 FROM ORDERLINES
 WHERE (ORDER_NO BETWEEN '1040000' AND '1060000')
    GO
    UPDATE ORDERLINES03
    SET OLID = '3'
    GO

4. INSERT INTO ORDERLINES04 ([ORDER_NO], [LINE_NO],
 [CROSS_REF], [USED_BUT_NOT_PRICED], [LOST],  ORIG_COMM])
 SELECT *
 FROM ORDERLINES
 WHERE (ORDER ORDER_NO >= '1060000')
    GO
    UPDATE ORDERLINES04
    SET OLID = '4'
    GO


 III. Build Constraints

For the Query Processor to know that each partitioned table contains only a certain type of data, we need to build CHECK constraints on each table on the ID that we have partitioned. Hence we will build CHECK constraints on OLID.                        

 1. ALTER TABLE ORDERLINES01
   ADD CONSTRAINT CK_OL1 CHECK (OLID=1)
  2. ALTER TABLE ORDERLINES02
   ADD CONSTRAINT CK_OL2 CHECK (OLID=2)
  3. ALTER TABLE ORDERLINES03
   ADD CONSTRAINT CK_OL3 CHECK (OLID=3)
  4. ALTER TABLE ORDERLINES04
   ADD CONSTRAINT CK_OL4 CHECK (OLID=4)

IV. Build the View

CREATE VIEW ORDERLINES
   AS
    SELECT * FROM ORDERLINES01
   UNION ALL
    SELECT * FROM ORDERLINES02
   UNION ALL
    SELECT * FROM ORDERLINES03
   UNION ALL
    SELECT * FROM ORDERLINES04

Conclusion 

The View shown above is the same as the original ORDERLINES table. But a query like

SELECT * FROM ORDERLINES WHERE OLID=2,

will not seek all the ORDERLINES records. It will limit the seek to ORDERLINES02 table only.

April 10, 2007

Oracle DBA Checklist

Filed under: Oracle — johnjacob @ 11:19 PM

 This checklist is useful for practising Oracle DBA.

Performance Tuning in Oracle

Filed under: Oracle — johnjacob @ 10:57 PM

Oracle9i’s principle-based approach, the principles for Tuning, in order of priority, are:

  1. Define the problem clearly and then formulate a tuning goal.
  2. Examine the host system and gather Oracle statistics.
  3. Compare the identified problem to the common performance problems identified by Oracle in the Oracle9i Database Performance Methods (Release 1)/Database Performance Planning (Release 2).
  4. Use the statistics gathered in the second step to get a conceptual picture of what might be happening on the system.
  5. Identify the changes to be made and then implement those changes.
  6. Determine whether the objectives identified in step one have been met. If they have, stop tuning. If not, repeat steps five and six until the tuning goal is met.

Read more here.

Read an important article here.

Next Page »

Blog at WordPress.com.