Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can i read my emails on lamp ftp 4 70
PHP Underscores vs. Directory separators 5 46
PHP Curl Problem 10 73
Load string Array from file 23 42
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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.

732 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