问答详情
源自:2-6 [PDO] prepare()和execute()方法执行查询语句

老师你好,请问我这里怎么加了PDO::FETCH_ASSOC后就没有东西显示里,用setfetchmode一样也没有东西

提问者:小小攻城狮 2014-09-01 23:50

个回答

  • King
    2014-09-02 10:02:07

    应该大写 你试试^_^...

  • 倾城恋雨
    2014-11-04 11:02:49

    设置fetchmode,应该放在execute方法的后面吧?

  • 小小攻城狮
    2014-09-01 23:51:00

    <?php
        $pdo=new PDO('mysql:host=localhost;dbname=test','root','123456');
        try{
        $sql='select * from user';
        $stam=$pdo->prepare($sql);
        //var_dump($stam);
        $stam->setfetchmode(pdo::fetch_assoc);
        $res=$stam->execute();

        print_r('<pre>');
        $row=$stam->fetchall();
        print_r($row);
        // if($res){
        //     while ($row=$stam->setfetchmode()) {
        //         print_r($row);
        //         echo '<hr />';
        //     }
        // }
    }
        catch(pdoexception $e){
            echo $e->getmessage();
        }