您的位置:首页 > 数据库

magento数据库处理的一些方法

2012-02-23 11:35 204 查看
<?php

//打印用户

$resource = Mage::getSingleton('core/resource');

$conn     = $resource->getConnection('core_read');

$results  = $conn->query('SELECT * FROM admin_user')->fetchAll();

echo '<pre>';

var_export($results);

echo '</pre>';

?>

<?php

//打印session

$singleton = Mage::getSingleton('catalog/session');

echo '<pre>';

var_export($singleton->debug());

echo '</pre>';

?>

<?php

  $conf = array(

  'host' => 'localhost',

  'username' => 'root',

  'password' => 'pwd',

  'dbname' => 'wordpress' // you can any database name here

  );

  $_resource = Mage::getSingleton('core/resource');

  //Creating new connection to new server and new database

  $_conn = $_resource->createConnection('customConnection',  

  'pdo_mysql', $conf);

  $results  = $_conn->query('SELECT * FROM wp_posts')->fetchAll();

  echo '<pre>';

  print_r($results);

  echo '</pre>';

?>

<?php

//连接数据库

$conf = array(

    'host' => 'localhost',

    'username' => 'root',

    'password' => '',

    'dbname' => 'hhl' // you can any database name here

);

$_resource = Mage::getSingleton('core/resource');

//Creating new connection to new server and new database

$_conn = $_resource->createConnection('customConnection',

    'pdo_mysql', $conf);

$results  = $_conn->query('SELECT * FROM hhl_activety')->fetchAll();

echo '<pre>';

print_r($results);

echo '</pre>';

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息