<tfoot id='MvOya'></tfoot>

      <i id='MvOya'><tr id='MvOya'><dt id='MvOya'><q id='MvOya'><span id='MvOya'><b id='MvOya'><form id='MvOya'><ins id='MvOya'></ins><ul id='MvOya'></ul><sub id='MvOya'></sub></form><legend id='MvOya'></legend><bdo id='MvOya'><pre id='MvOya'><center id='MvOya'></center></pre></bdo></b><th id='MvOya'></th></span></q></dt></tr></i><div id='MvOya'><tfoot id='MvOya'></tfoot><dl id='MvOya'><fieldset id='MvOya'></fieldset></dl></div>
      • <bdo id='MvOya'></bdo><ul id='MvOya'></ul>

      <small id='MvOya'></small><noframes id='MvOya'>

      <legend id='MvOya'><style id='MvOya'><dir id='MvOya'><q id='MvOya'></q></dir></style></legend>
    1. 使用框架将独立脚本连接到 joomla DB

      Connect standalone script to joomla DB using framework(使用框架将独立脚本连接到 joomla DB)

        • <small id='gWE7B'></small><noframes id='gWE7B'>

          • <i id='gWE7B'><tr id='gWE7B'><dt id='gWE7B'><q id='gWE7B'><span id='gWE7B'><b id='gWE7B'><form id='gWE7B'><ins id='gWE7B'></ins><ul id='gWE7B'></ul><sub id='gWE7B'></sub></form><legend id='gWE7B'></legend><bdo id='gWE7B'><pre id='gWE7B'><center id='gWE7B'></center></pre></bdo></b><th id='gWE7B'></th></span></q></dt></tr></i><div id='gWE7B'><tfoot id='gWE7B'></tfoot><dl id='gWE7B'><fieldset id='gWE7B'></fieldset></dl></div>
                <tbody id='gWE7B'></tbody>
              • <bdo id='gWE7B'></bdo><ul id='gWE7B'></ul>

                <tfoot id='gWE7B'></tfoot>
                <legend id='gWE7B'><style id='gWE7B'><dir id='gWE7B'><q id='gWE7B'></q></dir></style></legend>
                本文介绍了使用框架将独立脚本连接到 joomla DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前正在编写一个脚本,该脚本将作为 cronjob 运行,以使用 joomla 数据库中的值进行一些计算,因为该脚本不会通过 joomla 作为插件等访问,我需要与它进行数据库连接.

                Im currently writing a script which will be run as a cronjob to do some calculations using values out of the joomla database, Because this script is not going to be accessed via joomla as a plugin etc i need to do DB connections with it.

                我试图做的是使用 Joomla 框架来完成所有工作(连接、查询等),以实现安全性和可移植性(而不是在此脚本中使用另一组登录凭据,所有这些都由 Joomla 处理)配置)

                What im attempting to do is use the Joomla framework to do all the work(Connection, queries, etc) for security and also portability purposes (instead of having another set of the login credentials in this script its all handled by the Joomla config)

                我已经尽力了,但是当我运行脚本时出现以下错误:

                I have done the best i can but when i run the script i get the following error:

                Database Error: Unable to connect to the database:Could not connect to MySQL
                

                我已经打印出变量并确保 mysql 的连接详细信息是正确的(它们是正确的).

                I have printed out the variable and made sure that the connection details for mysql are correct (which they are).

                我当前的代码是:

                <?php
                //init Joomla Framework
                define( '_JEXEC', 1 );
                define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' ));
                define( 'DS', DIRECTORY_SEPARATOR );
                
                require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
                require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
                require_once( JPATH_CONFIGURATION   .DS.'configuration.php' );
                require_once ( JPATH_BASE .DS.'includes'.DS.'database.php' );
                require_once ( JPATH_LIBRARIES .DS.'joomla'.DS.'import.php' );
                
                //DB Connection
                $Config = new JConfig();
                
                $option['driver']   = $Config->dbtype;   // Database driver name
                $option['host']     = $Config->host;     // Database host name
                $option['user']     = $Config->user;     // User for database authentication
                $option['password'] = $Config->password; // Password for database authentication
                $option['database'] = $Config->db;       // Database name
                $option['prefix']   = $Config->dbprefix; // Database prefix (may be empty)
                
                $db = & JDatabase::getInstance($option);
                
                //DBQuery
                $database =& JFactory::getDBO();
                $query = "SELECT * FROM #__chronoforms_RD_NonDangerousGoods WHERE cf_id = 4;";
                $database->setQuery($query);
                $result = $database->query();
                print_r($result);
                ?>
                

                推荐答案

                试试这个

                   <?php
                        //init Joomla Framework
                        define( '_JEXEC', 1 );
                        define( 'DS', DIRECTORY_SEPARATOR );
                        define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..' ));
                
                
                        require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
                        require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
                
                        $mainframe = JFactory::getApplication('site');
                
                        //DBQuery
                        $database =& JFactory::getDBO();
                        $query = "SELECT * FROM #__chronoforms_RD_NonDangerousGoods WHERE cf_id = 4;";
                        $database->setQuery($query);
                        $result = $database->query();
                        print_r($result);
                    ?>
                

                这篇关于使用框架将独立脚本连接到 joomla DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    • <i id='dBoXG'><tr id='dBoXG'><dt id='dBoXG'><q id='dBoXG'><span id='dBoXG'><b id='dBoXG'><form id='dBoXG'><ins id='dBoXG'></ins><ul id='dBoXG'></ul><sub id='dBoXG'></sub></form><legend id='dBoXG'></legend><bdo id='dBoXG'><pre id='dBoXG'><center id='dBoXG'></center></pre></bdo></b><th id='dBoXG'></th></span></q></dt></tr></i><div id='dBoXG'><tfoot id='dBoXG'></tfoot><dl id='dBoXG'><fieldset id='dBoXG'></fieldset></dl></div>
                      <tfoot id='dBoXG'></tfoot>
                    • <small id='dBoXG'></small><noframes id='dBoXG'>

                        <tbody id='dBoXG'></tbody>

                        <legend id='dBoXG'><style id='dBoXG'><dir id='dBoXG'><q id='dBoXG'></q></dir></style></legend>
                          <bdo id='dBoXG'></bdo><ul id='dBoXG'></ul>