Skip to content

Instantly share code, notes, and snippets.

@QETHAN
Created August 31, 2014 08:10
Show Gist options
  • Save QETHAN/c7ac5db00889dca7bb45 to your computer and use it in GitHub Desktop.
Save QETHAN/c7ac5db00889dca7bb45 to your computer and use it in GitHub Desktop.

Revisions

  1. QETHAN created this gist Aug 31, 2014.
    14 changes: 14 additions & 0 deletions php MySQL连接
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <?php
    $link = mysql_connect('127.0.0.1', 'code1', '') or die('数据库连接失败');
    mysql_select_db('code1');
    mysql_query("set names 'utf8'");
    $result = mysql_query('select * from user limit 1');
    $row = mysql_fetch_array($result);
    print_r($row);


    PDO扩展
    $dsn = 'mysql:dbname=testdb;host=127.0.0.1';
    $user = 'dbuser';
    $password = 'dbpass';
    $dbh = new PDO($dsn, $user, $password);