PDO Get Single Value Of Coulmn Operation

Description

Get single value for the coulmn passed as variable.

Function Reference :
 
       			array dbGetVariable($tablename,$variable[, array $select_where_condition=array()]) 
             

Parameters

Name Type Required Parameter Info Example
table_name string Yes The name of the table to select records any table name like employee_table,user_table
variable string Required The coulmn name of the table "username" or "gender"
select_where_condition associative array Optional Associative array with key as column name and values as column value for where clause array("gender"=>"male")

Examples

               	 <?php
                  $sdb= new SimplifiedDB(); 
                  $sdb->dbConnect("localhost","username","password","dbuser"); 
                  $sdb->dbGetVariable("users","username",array("userId"=>1)); 
	           ?> 
              

Result

Returns array of values. You can define which type of array you needs using $sdb->fetch_mode="ASSOC" or $sdb->fetch_mode="NUM" etc. By default, it retrives associative array.

If you use print_r($result_array), it will show output as in following format.
Array ( [0] => Array ( [username] => Ram ) )

Debuging

Debug Operation Result/Output
$sdb->query SELECT `username` FROM `users` WHERE `userId`=?
$sdb->last_insert_id
$sdb->rows_affected
$sdb->message_info Connected to database
$sdb->error_info

More Examples

 
            	// Most basic example, selecting all columns and rows of table 'users'
            	$result=$sdb->dbGetVariable("user_roles","role_name",array("roleid"=>7));;