Solved

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

Posted on 2009-05-06
3
1,627 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

18 Experts available now in Live!

Get 1:1 Help Now