Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

617 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