Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

第 17 章 Doctrine

目錄

17.1. example

17.1. example

		
<?php
use Doctrine\Common\ClassLoader;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Configuration;

require 'Doctrine/Common/ClassLoader.php';

$classLoader = new ClassLoader('Doctrine', '/www/DoctrineDBAL-2.3.4/');
$classLoader->register();

$config = new Configuration();

$connectionParams = array(
    'dbname' => 'test',
    'user' => 'www',
    'password' => 'passw0rd',
    'host' => '192.168.2.1',
    'driver' => 'pdo_mysql',
);
$conn = DriverManager::getConnection($connectionParams, $config);

$sql = "SELECT * FROM members limit 5";
$stmt = $conn->query($sql);

while ($row = $stmt->fetch()) {
    printf("%s\r\n", $row['username']);
}