Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.4k views
in Plugins by
edited by

how to use Q2A functions for database in external php file like qa_db_query_sub()
 

If i use traditional sql queries then first it need to connect to database

(using @mysql_connect ()  )  so i dont want to write database login detais again and again. That is why i want to connect Q2A with external php page.

Please give any example

Q2A version: 1.5.1

3 Answers

0 votes
by
selected by
 
Best answer

This should cover it. If you include this in your script, you can access the Q2A functions.

 

$GLOBALS['k_dir_root'] = "server path to your web root";

define('QA_BASE_DIR', $GLOBALS['k_dir_root']);

require_once $GLOBALS['k_dir_root'].'qa-include/qa-base.php';

require_once QA_INCLUDE_DIR.'qa-db-admin.php';
require_once QA_INCLUDE_DIR.'qa-db-maxima.php';
require_once QA_INCLUDE_DIR.'qa-db-post-create.php';
require_once QA_INCLUDE_DIR.'qa-db-points.php';
require_once QA_INCLUDE_DIR.'qa-db-hotness.php';
require_once QA_INCLUDE_DIR.'qa-db-users.php'; // optional
require_once QA_INCLUDE_DIR.'qa-util-string.php';
require_once QA_INCLUDE_DIR.'qa-db.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-post-update.php';
require_once QA_INCLUDE_DIR.'qa-app-posts.php';
 
0 votes
by

If you use the Q2A database functions like qa_db_query_sub(), it will connect to the database automatically.

+1 vote
by

Here is one example of a php file, you only need to include the qa-base.php to use the core functions:

<?php
    // load q2a core
    require_once '../../qa-include/qa-base.php';

    $output = '';
    
    $unlock = qa_get('id'); // get id parameter from URL
    if($unlock=='mykeyword')
    {
        $usercount = qa_db_read_one_value(
                                qa_db_query_sub('SELECT COUNT(userid) FROM `^users`');
        $output .= '
            <p>You have '.$usercount.' users in your forum.</p>
        ';
        echo $output;
    }
    exit();
?>

also check http://docs.question2answer.org/code/external/

...