search

Home  >  Q&A  >  body text

php - pdo 获取总列数

pdo 怎么获取总列数

$cols=mysql_num_fields($result);//总列数
$total=mysql_num_rows($result);//总条数

用pdo 怎么写

高洛峰高洛峰2784 days ago935

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-11 10:19:01

    SQL语句啊.COUNT()

    try{
            $pdo = new \PDO('mysql:dbname=test;host=localhost','root','');
            $pdo->exec('SET NAMES utf8 ');
            $stm = $pdo->query(' SELECT COUNT(*) FORM xxx ' );
            $data = $stmt->fetch( PDO::FETCH_NUM);
    }catch(PDOException $e)
    {
        die($e->getMessage());
    }
    

    reply
    0
  • 高洛峰

    高洛峰2017-04-11 10:19:01

    $pdo = new PDO('mysql:test', 'root', '123456');
    $count = $pdo->exec("select COUNT(1) FROM tables");

    reply
    0
  • Cancelreply