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;  
     }