Tuesday, July 5, 2016

Change enum column value when matching condition

The example shows how to rename the existing enum value OLD_VALUE to NEW_VALUE. 

Example 1:
 UPDATE `userinfo` set `account_type` = 'Houseowner' where  
 `account_type` = 'dipen';  

Example 2:
 update userinfo set account_type = replace(account_type, 'normal', 'hello')  

Note: Your enum must contain new value otherwise your value will be replaced with empty value.

Wednesday, June 29, 2016

Connecting mssql with php

  try  
     {  
       //$con = new PDO("odbc:Driver={SQL Server};Server=192.168.1.1;Database=time_trax",'dipen','dipen123');  
       $con = new PDO("odbc:Driver={SQL Server};Server=192.168.1.1;Database=DBTRAX",'govinda','nepal123');  
       $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
       //$sql ="SELECT * FROM EMP_DETAIL WHERE EMP_ID = 1";  
       $sql = "SELECT  
           dbo.EMP_DETAIL.EMP_ID,  
           dbo.EMP_DETAIL.EMP_TITLE,  
           dbo.EMP_DETAIL.EMP_FIRSTNAME  
           FROM [dbo].[EMP_DETAIL]  
           WHERE EMP_ID = '1'" ;  
       $sth = $con->prepare($sql);  
       $sth->execute();  
       $result = $sth->fetchAll();  
       return $result;  
     }  
     catch(Exception $e)  
     {  
       return "Error occured" . $e;  
     }  

Wednesday, May 6, 2015

Encryption in code igniter

Encryption
 </pre>  
 this->load->library('encrypt');  
 $enc_username=$this->encrypt->encode($username);  
 $enc_username=str_replace(array('+', '/', '='), array('-', '_', '~'), $enc_username);  
 <pre>  

Decryption
 </pre>  
 $this->load->library('encrypt');  
 $dec_username=str_replace(array('-', '_', '~'), array('+', '/', '='), $enc_username);  
 $dec_username=$this->encrypt->decode($dec_username);  
 <pre>  

For further info
matin.pariab
roshanbh
smarttutorials
Code Igniter

Sunday, May 3, 2015

Get the id of input on keyup


 <script>   
   function myFunction(val)  
   {  
     var id = val.getAttribute('id');  
     alert("The input value has changed. The id of input is "+ id);  
   }  
 </script>  
 In this line i have dynamically generated the input according to length of the array.  
 <input style="width: 90%;" type="text" required="" name="mac[]" id="mac_<?php echo $i;?>" onkeyup="myFunction(this)" />  
 If you have fixed number of inputs then use this code  
 <input style="width: 90%;" type="text" required="" name="mac[]" id="mac" onkeyup="myFunction(this)" />   

Sunday, April 5, 2015

Tuesday, October 21, 2014

String function in php


 <?php  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      //replacing tea from above sentence by milk with str_replace function  
      echo str_replace("tea","milk",$sentence);  
 ?>  

Regular expression example 3


 <?php  
      // type of regular expression  
      //posix style regular exrpession  
      //pcre style regular expression  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      $regexp="love|lob|feelings";  
      // search the search the mentioned words in the sentence  
      if(ereg($regexp,$sentence))  
      {  
           echo "regular expression is true";  
      }  
      else  
      {  
           echo "regular expression is false";  
      }  
 ?>  

Regular expression example 2


 <?php  
      // type of regular expression  
      //posix style regular exrpession  
      //pcre style regular expression  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      //^ search the lob word in the begining of the sentence  
      if(ereg("^lob",$sentence))  
      {  
           echo "regular expression is true";  
      }  
      else  
      {  
           echo "regular expression is false";  
      }  
 ?>  

Regular expression example 1


 <?php  
      // type of regular expression  
      //posix style regular exrpession  
      //pcre style regular expression  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      if(ereg("lob",$sentence))  
      {  
           echo "regular expression is true";  
      }  
      else  
      {  
           echo "regular expression is false";  
      }  
 ?>  

Sunday, October 5, 2014

Get form data (get method)

1:  <?php  
2:       $test = $_GET["test"];  
3:       $test2 = $_GET["test2"];  
4:       echo $test;  
5:       echo "</br>".$test2;  
6:       $len = strlen($test);  
7:       if($len > 0)  
8:       {  
9:            echo "</br>".$len + strlen($test2);  
10:       }  
11:       else  
12:       {  
13:            echo "error : there is no input";  
14:       }  
15:  ?>  
16:  <form method = "GET" action = "Basic3.php">  
17:       <input type= "text" name="test" >  
18:       <input type="text" name="test2">  
19:       <input type="submit" value="submit">  
20:  </form>  

Posting form data (post method)

1:  <?php  
2:       $temp = Array("one","two","cow","toe");  
3:       echo count($temp);  
4:       echo "</br>" . $temp[1];  
5:       for($i=0 ; $i < count($temp) ; $i++)  
6:       {  
7:            echo "</br>Loop #$i $temp[$i]" ;  
8:       }  
9:       $var =5;  
10:       if ($var == 4)  
11:       {  
12:            echo "value is 4";  
13:       }  
14:       elseif ($var == 5)  
15:       {  
16:            echo "value is 5";  
17:       }  
18:  ?>  

Array


1:  <?php  
2:       $temp = Array("one","two","cow","toe");  
3:       echo count($temp);  
4:       echo "</br>" . $temp[1];  
5:       for($i=0 ; $i < count($temp) ; $i++)  
6:       {  
7:            echo "</br>Loop #$i $temp[$i]" ;  
8:       }  
9:       $var =5;  
10:       if ($var == 4)  
11:       {  
12:            echo "value is 4";  
13:       }  
14:       elseif ($var == 5)  
15:       {  
16:            echo "value is 5";  
17:       }  
18:  ?>  

Thursday, September 25, 2014

Declearing variables in php

 <html>  
 <head>  
      <title>first php page</title>  
 </head>  
 <body>  
      hi there!<br>  
      <?php  
           //declearing variables  
           $myInteer = 5 ;  
           $myFloat =  55.63 ;  
           $myString = "Into the wild" ;        
           $todaysDate = date("m/d/y");  
           $firstName = "Dipen" ;  
           $lastName = "lama";  
           $Name = $firstName ." ". $lastName;  
           echo "Hey!<br>";  
           echo $firstName . " ". $lastName . "<br>";  
           echo $Name;       
           echo "The date was";  
           echo date("m/d/Y");  
           echo $todaysDate;  
           //echo "$myInteger + $myFloat=" .($myInteger + $myFloat) . "<br>" ;  
           echo "?";       
      ?>  
      <br>  
      ok... i'm now not in a script.<br>  
      The time was<? echo date("h:i;s a");?><br>  
      Your IP address was:<? echo getenv("REMOTE_ADDR");?>  
 <body>   
 </html>  

First basic php tutorial V2

 <html>  
 <head>  
      <title>first php page</title>  
 </head>  
 <body>  
      hi there!<br>  
      <?php  
           echo "Dipen!<br>";  
           echo "The date was";  
           echo date("m/d/y");  
           echo"?";  
      ?>  
      <br>  
      ok.... I'm now not in a script<br>  
      did you that the time was<? echo date("h:i:s a");?>  
      Your IP address was:<? echo getenv("REMOTE_ADDR");?>  
 <body>   
 </html>