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']);
}