本文整理汇总了PHP中PDO::setATtribute方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::setATtribute方法的具体用法?PHP PDO::setATtribute怎么用?PHP PDO::setATtribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::setATtribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
// database connection info
$dbInfo = array('host' => 'localhost', 'name' => 'doctrine_website', 'user' => 'root', 'pass' => '');
// connect to the database
$db = new PDO('mysql:host=' . $dbInfo['host'] . ';dbname=' . $dbInfo['name'] . ';', $dbInfo['user'], $dbInfo['pass']);
$db->setATtribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT\n b.id as blog_id,\n b.name as blog_title,\n b.slug as blog_slug,\n b.body as blog_body,\n b.created_at as blog_date,\n c.poster as comment_poster,\n c.id as comment_id,\n c.created_at as comment_date,\n c.body as comment_body\nFROM comment c INNER JOIN blog_post b ON b.id = c.record_id ORDER BY b.id";
$result = $db->query($sqlQuery);
$rawdata = $result->fetchAll(PDO::FETCH_ASSOC);
// Build the comments sql for all the blog posts
$itemXml = '';
$lastId = null;
$first = true;
foreach ($rawdata as $data) {
if ($lastId != $data['blog_id']) {
if ($first) {
$first = false;
} else {
$itemXml .= '</item>';
}
$itemXml .= '
<item>
<!-- title of article -->
<title>' . $data['blog_title'] . '</title>
<!-- absolute URI to article -->
<link>http://www.doctrine-project.org/blog/' . $data['blog_slug'] . '</link>
<!-- thread body; use cdata; html allowed (though will be formatted to DISQUS specs) -->
<content:encoded><![CDATA[' . $data['blog_body'] . ']]></content:encoded>
<!-- value used within disqus_identifier; usually internal identifier of article -->
<dsq:thread_identifier>' . $data['blog_slug'] . '</dsq:thread_identifier>