Friday, April 27, 2012

PHP Error Handling via htaccess

We can restrict PHP Errors via htaccess

PHP error handling for production servers

php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log

php_flag display_errors off
php_flag html_errors off
 
# prevent access to PHP error log
<Files PHP_errors.log>
 Order allow,deny
 Deny from all
 Satisfy All
</Files> 

# PHP error handling for production servers
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
# [see footnote 3] # php_value error_reporting 999999999
php_value error_reporting -1
php_value log_errors_max_len 0

<Files PHP_errors.log>
 Order allow,deny
 Deny from all
 Satisfy All
</Files>

Thursday, April 26, 2012

How to fill an array with values specifying keys

array_fill_keysFill an array with values, specifying keys

<?php
$keys 
= array('foo'510'bar');$a array_fill_keys($keys'banana');print_r($a);?>


The above output

Array ( [foo] => banana [5] => banana [10] => banana [bar] => banana )  

Tuesday, April 24, 2012

document.formname.submit() is not a function or not working

When we are trying to submit a form using java script some times it will not working properly.

Find the below case

I have form like this

<form name="myform" method="post">
  <input type="text" name="name" value="">
  <input type="submit" name="submit" value="GO">
</form>

Here i am trying to submit the the form using java script
<script>
      document.myform.submit();
</script>

Error:- document.myform.submit() not a function

I have solution here change form submit name

<input type="submit" name="register" values="Go">

Don't put the form submit name as submit.





Number format in PHP

number_formatFormat a number with grouped thousands

<?php

$number 
1234.56;
// english notation (default)$english_format_number number_format($number);// 1,235

// French notation
$nombre_format_francais number_format($number2','' ');


?> 

Monday, April 23, 2012

How to create index in mysql table feild

We can create the index for table field very easily. Find the below code

ALTER TABLE `product_name` ADD INDEX ( `deal_id` ) ;

Explain advantages of MyISAM over InnoDB?


MyISAM table is stored in a separate files, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace etc

Explain advantages of InnoDB over MyISAM?

Row-level locking, transactions, foreign key constraints and crash recovery.

How to find number of unique values in table?

Using mysql query we can find the distinct values find the below query for your reffrence


SELECT COUNT (DISTINCT empname) FROM emp;

What are the different tables engines in MySQL

1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage engine as of MySQL 3.23 and as a result if
we do not specify the table name explicitly it will be assigned to the
default engine.

In how many ways we can retrieve the data in the result set of MySQL using PHP?

We can fetch the data from the database by 4 ways

1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc

What’s the default port for MySQL Server?

The Default port of mysql is: 3306

How to write IN query in mysql?

Suppose if you want to employee names from empl table who is having emp_id is 1,4,6 or 8

Check the below code for solution

SELECT emp_name FROM empWHERE emp_id IN (1, 4, 6, 8)

How do you get the number of rows affected by query?

SELECT COUNT (user_id) FROM users would only return the number of user_id’s.

How delete dublicate records in mysql table?

Find the following code using this code we can delete duplicate records

If you want to delete total dublicate records write check with the below code

delete from emp_sal USING emp_sal, emp_sal as vtable WHERE (NOT emp_sal.id=vtable.id) AND (emp_sal.sal=vtable.sal)

If you want to delete more one dublicate records check the below code

delete from emp_sal USING emp_sal, emp_sal as vtable WHERE emp_sal.id > vtable.id AND (emp_sal.sal=vtable.sal)

Thursday, April 19, 2012

How to add google search results to our website

The following code shows the google search results shows to our website

<!-- SiteSearch Google -->
<form method="get" action="http://home.wangjianshuo.com/archives/20060120_search_this_site.htm" target="_top">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a>
</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="home.wangjianshuo.com"></input>
<input type="text" name="q" size="20" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Search"></input>
</td></tr>
<tr>
<td> </td>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" checked="checked"></input>
<font size="-1" color="#000000">Web</font>
</td>
<td>
<input type="radio" name="sitesearch" value="home.wangjianshuo.com"></input>
<font size="-1" color="#000000">home.wangjianshuo.com</font>
</td>
</tr>
</table>
<input type="hidden" name="client" value="pub-8513779941474461"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="channel" value="6801625507"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="safe" value="active"></input>
<input type="hidden" name="flav" value="0000"></input>
<input type="hidden" name="sig" value="NdyQdGFpJnNH_B3d"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11"></input>
<input type="hidden" name="hl" value="en"></input>
</td></tr></table>
</form>
<!-- SiteSearch Google -->
Search Result Code
<!-- Google Search Result Snippet Begins -->
<div id="googleSearchUnitIframe"></div>
<script type="text/javascript">
var googleSearchIframeName = 'googleSearchUnitIframe';
var googleSearchFrameWidth = 650;
var googleSearchFrameHeight = 1300;
var googleSearchFrameborder = 0 ;
</script>
<script type="text/javascript"
src="http://www.google.com/afsonline/show_afs_search.js">
</script>
<!-- Google Search Result Snippet Ends -->

Thursday, April 12, 2012

Google Apps OPen ID with PHP

Google supports OpenID authentication or behaves as openid identity provider, using Google Apps accounts.
This is especially useful for companies to unite other internal services with Google Apps single sign-in point. This is related to Standard edition as well.

I have done my requirement with Google Apps OPEN-ID

Please go through with below URLS. You will get the solution

http://a32.me/2010/02/google-apps-premier-federated-login-with-php/ 

Tuesday, April 10, 2012

ereg is deprecated` errors in PHP 5.3+

If your working with PHP 5.3 or heighter, chances are high you’re going to run into a few warnings or deprecated function messages.
  
TO
ereg
('\.([^\.]*$)', string $string [, array &$regs ] );

Change 
preg_match('/\.([^\.]*$)/', $subject$matches);

How to send an error messages one log using PHP?

error_logSend an error message somewhere

error_log("You messed up!"3"/var/tmp/my-errors.log");

 

error_reporting in PHP?

<?php
// Turn off all error reportingerror_reporting(0);
// Report simple running errorserror_reporting(E_ERROR E_WARNING E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL E_NOTICE);
// Report all PHP errors (see changelog)error_reporting(E_ALL);
// Report all PHP errorserror_reporting(-1);
// Same as error_reporting(E_ALL);ini_set('error_reporting'E_ALL);
?>

Sunday, April 8, 2012

Difference between Php4 and Php5

Find the below major changes in PHP4 & PHP5
  • PHP 5, the object model was rewritten to allow for better performance and more features
  • We can define abstract class
  • public,private and protected methods interdused
  • we can pass values by reffrence
  • In PHP5 new array functions are interduced
  • PHP 5 are the inclusions of Visibility, Abstract, Final Classes and method magic methods, interfaces, cloning,typehinting etc
  • New error level named E_STRICT has been introduced.