php - SELECT 1 FROM table, weird print_r result -


from have read, when executing following sql command , fetchall() on table 6 rows , 11 columns:

$sql = "select 1 table"; $sqlprepared = $conn->prepare($sql) $sqlprepared->execute() $result = $sqlprepared->fetchall(); $print_r($result); 

i should getting 6 rows of 1 value in each row, value 1 inside each of values. however, getting 6 rows of 2 values in each row, value 1 inside each of values:

array (    [0] => array (      [1] => 1      [2] => 1 )    [1] => array (      [1] => 1      [2] => 1 )    [2] => array (      [1] => 1      [2] => 1 )    [3] => array (      [1] => 1      [2] => 1 )    [4] => array (      [1] => 1      [2] => 1 )    [5] => array (      [1] => 1      [2] => 1 )  )  

question 1: why getting 2 values each array instead of 1?

question 2: instead of inner arrays being

 array (      [1] => 1 ... 

why doesn't start [0]?:

 array (      [0] => 1 ... 

if don't provide flag on ->fetchall() method, includes associative , numeric indices on multidimensional array row.

so when used select 1 from, associative index 1 (meaning, column name 1), , since array keys unique, numeric index adjusted, numeric index value pair assigned 2.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -