这是我在 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/