fetchColumnは特定のカラムを全て返すというものだと思うのですが、違うのですか。
実行結果はstateJカラム全件の0,0,1だと予想していましたが、常に1列1行なのでしょうか。
https://teratail.com/questions/100701
参考
PHP
1public function test() 2 { 3 $sql = sprintf("select state from todos"); 4 $stmt = $this->_db->query($sql); 5 $results = $stmt->fetchColumn(); 6 return $results; 7 } 8//実行処理のみ抜粋 9$results = $todoApp ->test(); 10var_dump($results);
SQL
1CREATE TABLE `todos` ( 2 `id` int(11) NOT NULL, 3 `state` tinyint(1) DEFAULT '0', 4 `title` text 5) ENGINE=InnoDB DEFAULT CHARSET=utf8; 6 7-- 8-- Dumping data for table `todos` 9-- 10 11INSERT INTO `todos` (`id`, `state`, `title`) VALUES 12(1, 0, 'todo 0'), 13(2, 0, 'todo 1'), 14(3, 1, 'todo 2'); 15 16-- 17-- Indexes for dumped tables 18-- 19 20-- 21-- Indexes for table `todos` 22-- 23ALTER TABLE `todos` 24 ADD PRIMARY KEY (`id`); 25 26-- 27-- AUTO_INCREMENT for dumped tables 28-- 29 30-- 31-- AUTO_INCREMENT for table `todos` 32-- 33ALTER TABLE `todos` 34 MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; 35
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/21 10:53