//因?yàn)檫B接SQLite數(shù)據(jù)庫(kù)不需要用戶名和密碼,所以,DSN 中僅指定了驅(qū)動(dòng)和數(shù)據(jù)源位置(文件路徑) $db = new PDO('sqlite:/path/to/database.sq3'); //MySQL 連接 $db = new PDO('mysql:host=hostname;dbname=databasename;charset=utf8', 'username', 'password'); //PostgreSQL 連接 $db = new PDO('pgsql:host=hostname;port=portnumber;dbname=databasename;user=username;password=password');
$dsn = 'mysql:host=localhost;dbname=test'; $username = 'testuser'; $password = 'testpass'; try { $dbh = new PDO($dsn, $username, $password); echo "連接成功\n"; } catch (PDOException $e) { echo "連接失敗:" . $e->getMessage() . "\n"; }
上一篇php ds 拼接
下一篇php dround