Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I access the Joomla database from my own php file.

Posted on 2009-05-06
3
Medium Priority
?
1,633 Views
Last Modified: 2013-12-12
I'm trying to make a database call on a Joomla/Virtuemart website.  I know that Joomla has it's own db class, but I can't seem to get it to work with my own file.

Basically, this is what I have.  What important piece am I missing=?

<?php

   global $database;
   
   $id = $_GET['uid'];
   

    $sql = "SELECT cv_id FROM cv_user WHERE vm_id='{$id}' LIMIT 1";
    $database->setQuery($sql);
   $user_id = $database->loadResult();
   
   echo $user_id;

?>




0
Comment
Question by:krussell222
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 24317081
Hello,
You are missing imports.
For example you need to import configuration file.

Or is this example code in some class or file which is based on joomla.


Why not to create your own connection with mysql_connect?
0
 

Author Comment

by:krussell222
ID: 24317095
No.. what you see is what you get... no imports.  I'm looking to find exactly which classes I need to import.  I could use my own connection, but just figured I'd use what is already there w/Joomla.  Bad idea?
0
 
LVL 11

Accepted Solution

by:
f_o_o_k_y earned 2000 total points
ID: 24317147
It depends on what you want to do. For example joomla have table adapters for each table.
But if you want to do some really simply things the quickest way is to import joomla config and then create your own connecion and sql syntax.

here is somethinfg about joomla database.
http://joomlatp.com/joomla-database/
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question