LoginSignup
2
2

More than 5 years have passed since last update.

PHPでMySQLに繋いでselect文を発行

Posted at

前提

PHPからMySQLに接続する にて接続を行っている

コード(処理部分のみ)

テーブル:hogetable、のフィールド:hogefieldの内容をdumpする。

$sql = "select * from hogetable";
foreach ($dbh->query($sql) as $hoge) {
    var_dump($hoge['hogefield']);
}

テーブル:hogetableにおいてselectで取得した行数をechoする。

echo $dbh->query("select count(*) from hogetable")->fetchColumn();

所感

$dbh->query(クエリ)ってやると結果が連想配列な感じになるのね。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2