2013-02-21 99 views
2

这是我在Magento中使用的核心PHP代码。如何在Magento中使用外部数据库连接?

 $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方式的代码。

+0

检查这个我认为这将有助于.. http://stackoverflow.com/questions/4654379/how-to-connect-multiple-external-databases-in-magento – 2013-02-21 10:09:25

+0

谢谢@Rocksis但我认为这是漫长的道路....做外部数据库连接....! – 2013-02-21 11:34:16

+0

试着问你的问题http://magento.stackexchange.com here – 2013-04-26 10:53:55

回答

0

使用此MySQL的命令连接到外部数据库:

的MySQL -h clouddb.com -u根-p dbname;开发

它要求密码为根,然后输入密码,然后你就可以登录到您的外部数据库!