PDO Select Operation


Select records from the single table. You can provide columns to be selected and where clause with associative array of conditions with keys as columns and value as column value. Along with these function parameters, you can set group by columnname, order by columnname, limit, like, in , not in, between clause etc. This function will automatically creates query for you and select data.

Function Reference :
       			array dbSelect(string $table_name [, array $columns=array()] [, assoc. array $select_where_condition=array()]) 


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
columns array Optional Array of columns to be selected array("username","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")


                  $sdb= new SimplifiedDB(); 


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 ( [firstName] => Mike [email] => xyz1@gmail.com ) [1] => Array ( [firstName] => Adam [email] => dummy@gmail.com ) [2] => Array ( [firstName] => Goerge [email] => abc@gmail.com ) )


Debug Operation Result/Output
$sdb->query SELECT `firstName`,`email` FROM `users` WHERE `gender`=?
$sdb->message_info Connected to database

More Examples

            	// Most basic example, selecting all columns and rows of table 'users'
               	//selecting all columns of table 'users' where gender='male'

				// Applying group by, order by and limit conditions, you need to set them before calling select function

               	// Example of using != operator, similary you can use any valid operator like '>','<','>=','<=',
                 $result=$sdb->dbSelect("users",array("firstName","email"),array("gender !="=>"male"));					

               	// Example of using 'like'

               	// Example of using 'or' instead of 'and' in where condition

               	// Example of using count(*), you needs to make backticks(`)="" off to use that.
$result=$sdb->dbSelect("users",array("Count(*)","email"),array("role_id"=>10)); // Example of using Max, you needs to make backticks(`)="" off to use that. $sdb->backticks=""; $result=$sdb->dbSelect("users",array("Max(userid)")); // Example of using 'in' claues $sdb->in=array("role_id"=>"'10','8','12'"); $result=$sdb->dbSelect("users",array("userid")); // Example of using 'not in' clause $sdb->not_in=array("role_id"=>"'10','8','12'"); $result=$sdb->dbSelect("users",array("userid")); // Example of using 'group by ' and 'having' $sdb->group_by_column="role_id"; $sdb->having="sum(visits)>10 "; $result=$sdb->dbSelect("users",array("userid")); // Example of getting no of rows returned echo $sdb->rows_returned; // Example of setting different types of fetch mode $sdb->fetch_mode="ASSOC"; $sdb->fetch_mode="BOTH"; $sdb->fetch_mode="NUM"; $sdb->fetch_mode="OBJ"; $sdb->fetch_mode="COLUMN"; // example of using the same same column name for 'and','or' conditions $sdb->isSameColumns=true; $sdb->and_or_condition="or"; $result=$sdb->dbSelect("users",array("firstName","email"),array("gender"=>"male","gender1"=>"female"));