The simple query is like,
INSERT INTO table (date_field) VALUES (NULL);
But when we try to run this insert query through PHP application, where we don't know whether the variable is NULL or contain some value, it starts giving error. Here we need to do some programming and query manipulation as shown below,
<?
if(empty($dbDate)) $dbDate = '0000-00-00';
$myQry = "INSERT INTO table (date_field) VALUES (CASE $dbDate WHEN 0 THEN NULL ELSE TO_DATE('{$dbDate}', 'YYYY-MM-DD') END)";
/*Remaining code comes here */
?>
Search This Blog
Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
29 December 2010
17 November 2010
Windows Apache PHP and Postgres (WAPP Server)
BitNami WAPPStack includes Apache 2.2.16, PostgreSQL 9.0.0-1, PHP 5.2.14 and phpPgAdmin 4.2.2. phpPgAdmin is a web interface for administration of PostgreSQL. Steps to install and configure WAPP Server are given below,
Installation
Installation
- Download free copy of WAPP Server from http://bitnami.org/stack/wappstack
- Locate the downloaded file and double click the file to launch the installation.
- The WAPP Setup Wizard will appear. Click Next.
- At the Select Destination Location you can change the install directory. The default is C:\Program Files\BitNami WAPPStack. We will use the default directory. Click Next.
- Then you will be asked for PostgreSQL postgres user password. Enter the Password. A Postgres user account will be created with user name “postgres” and the password you have entered. This information will be then used to connect with PostgreSQL server, through command prompt or through phpPgAdmin. Click Next
- The default listening port for Apache is 80 and for PostgreSQL is 5432. If those ports are already in use by other applications, you will be prompted for alternate ports to use. Enter the alternate port if prompted. Click next
- You are now ready to begin the installation, screen will appear. Click next
- When installation is complete, “Completing the BitNami WAPP Stack Setup Wizard” page will appear. Click on Finish
- You can now launch your browser with http://localhost/
- The installation process will create several subfolders under the main installation directory i.e. C:\Program Files\BitNami WAPPStack
- Create your PHP files in C:\Program Files\BitNami WAPPStack\apache2\htdocs
- You can access your phpPgAdmin by opening a browser and typing http://127.0.0.1/phppgadmin. You will be asked for a username and password. As user name, use "administrator" and as password use the value specified during installation
- Once you are connected with phpPgAdmin, to connect with default Postgres database, click on the Postgres on left bar, it will again ask for database user name and password. As the user name, use “postgres” and as password use the value specified during installation
Labels:
PHP,
PostgreSQL
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
- Open your php.ini file
- Search for ‘short_open_tag’ directive
- The default value of ‘short_open_tag’ directive usually Off, now you can change it to On
- Save the php.ini
- Restart your PHP stacks to reflect the changes
Labels:
PHP
24 September 2010
How to install and configure WAMP Server?
Steps to install and configure WAMP Server are given below,
Installation
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.
- 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
Labels:
PHP
Subscribe to:
Posts (Atom)