php - 如何在 Magento 中使用外部数据库连接?

标签 php mysql magento-1.7 moodle

这是我在 Magento 中使用的核心 PHP 代码。

        $model_moodle = mysql_connect("localhost","root","123456")  
            or die("Unable to connect to MySQL");       
        //select a database to work with
        $selected = mysql_select_db("moodle",$model_moodle) 
          or die("Could not select moodle");
        //execute the SQL query and return records
        $result = mysql_query("SELECT id FROM mdl_course where shortname ='".$data."'");        
        //fetch tha data from the database 
        while ($row = mysql_fetch_array($result)) {        
           $course_id = $row['id'];//display the results          
        }
        //echo "Cource id is=".$course_id;
        //close the connection
        mysql_close($model_moodle);

我需要使用此代码但使用 Magento 外部数据库连接。
我在 Magento 中使用“Moodle”数据库。但我需要 Magento 方式的代码。

最佳答案

使用这个 mysql 命令连接到外部数据库:

mysql -h clouddb.com -u root -p 数据库名;

它会询问 root 的密码,然后输入密码,然后你就可以登录到你的外部数据库了!!

关于php - 如何在 Magento 中使用外部数据库连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14996367/

相关文章:

magento - 如何根据颜色和尺寸属性通过关联的产品图像更改可配置的产品主图像?

magento-1.7 - 第 : 行中属性集列的值无效(集不存在?)

php - htmlentities() 双重编码字符串中的实体

php - 使用 PHP 的 [min - max] 范围内的随机数

php - 将两个查询组合成一个需要第一个查询中的值的查询

php - 当从网络请求加载多个图像时,我应该返回图像数据还是图像的链接?

php - Magento 重新索引 + 目录页面问题

php - 数据库不更新,mysql_error不显示错误

php - “方法 [validateString] 不存在。”在 laravel 验证

mysql - 如何在 Hibernate 中为我使用外键列的 where 子句编写更新查询?