Solved

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

Posted on 2009-05-06
3
1,626 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
  • 2
3 Comments
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now