sql - PHP prepared statement -> only returns first letter from a column in database -


i have code

        $sql = "select name data id=? limit 0,1";         //prepares statement          $stmt = self::getconnection()->prepare($sql);         $stmt->bind_param("i", $id);         $ids = array(1,2,3);         foreach ($ids $key => $id) {             $stmt->execute();             $stmt->bind_result($name);             $stmt->fetch();             $stmt->store_result();              var_dump($name);         } 

my database table looks this

id | name 1  | first name 2  | second name 3  | third name 

now output looks this:

string(10) "first name"  string(1) "s"  string(1) "t" 

the first name correct. outputs first letter of following rows. don't know why. tried out column integer-type. worked. string-type column doesn't.

i tried change $ids-array in this: $ids = array(2,3,1). outputs

string(11) "second name"  string(1) "t"  string(1) "f" 

i have no clue do. see mistake?

edit:

php 5.5 , mysql 5.5.31 , var_dump:

edit 2:

-- phpmyadmin sql dump -- version 4.0.5 -- http://www.phpmyadmin.net -- -- host: rdbms -- erstellungszeit: 07. jun 2014 um 19:21 -- server version: 5.5.31-log -- php-version: 5.3.27  set sql_mode = "no_auto_value_on_zero"; set time_zone = "+00:00";   /*!40101 set @old_character_set_client=@@character_set_client */; /*!40101 set @old_character_set_results=@@character_set_results */; /*!40101 set @old_collation_connection=@@collation_connection */; /*!40101 set names utf8 */;  -- -- datenbank: `db1673555` --  -- --------------------------------------------------------   create table if not exists `data` (   `id` int(11) not null auto_increment,   `name` tinytext not null,   primary key (`id`) ) engine=innodb  default charset=utf8 auto_increment=4 ;   insert `data` (`id`, `name`) values (1, 'first name'), (2, 'second name'), (3, 'third name');  /*!40101 set character_set_client=@old_character_set_client */; /*!40101 set character_set_results=@old_character_set_results */; /*!40101 set collation_connection=@old_collation_connection */; 

i saw dump says use php 5.3. on website of strato 5.5

here's found. think reason it's in type tinytext. because when use database dump error reproduced on local pc. changed column type varchar 255 code work fine.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -