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.
php MySQL连接
<?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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment