How to query SQL from Joomla 1.7?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
whyknott
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Tue Nov 29, 2011 8:22 pm

How to query SQL from Joomla 1.7?

Post by whyknott » Tue Nov 29, 2011 8:43 pm

Hello- I was hoping to get some help in the area of How to query SQL from Joomla 1.7? I really am a newbie when it comes to this area of working with databases thru Joomla.

I need to connect to an external database outside of the Joomla built in one. The external database houses a simple table with 5 columns of info. I want to query that database and showcase some of the info on the main index.php page of my joomla 1.7 site.

Anyone know of the best way to go about this process and can actually break it down into steps?

Here is the page in development.. dev.runkles.com

scroll down to the very bottom where you see New Insurance customers, Average Savings and Total Savings Areas underneath each of those areas will be a number pulled in from the external database.

Help! ??? :(

Thanks
Kenny

User avatar
ranwilli
Joomla! Master
Joomla! Master
Posts: 19203
Joined: Sun Feb 19, 2006 6:47 pm
Location: Toledo, OH
Contact:

Re: How to query SQL from Joomla 1.7?

Post by ranwilli » Tue Nov 29, 2011 8:44 pm

It may be simpler to do it with Fabrik... OR to import the table into the Joomla database.
Don't HACK the Joomla! core, Instead "Extend" and/or "Override."
Stay ON the update path.
https://harpervance.com

whyknott
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Tue Nov 29, 2011 8:22 pm

Re: How to query SQL from Joomla 1.7?

Post by whyknott » Tue Nov 29, 2011 9:10 pm

Hi ranwilli -

I guess I'll have to Google what Fabrik is. The client is using another custom coded admin section from an external website outside of Joomla to dynamically update the information. So not sure I want to mess with that system so I was really just trying to connect to what the client already has setup. If I copied the info from the external database over to the Joomla database wouldn't that external admin need updated as well? Again, I'm a newbie when it comes to database and querying.

I was told that the code to display the numbers is done this way:

The code that calls the SQL stored procedure and then populates is right at the beginning of the "insurance.aspx.vb" file. (that code basically just fills numbers into the placeholders in the DIV's)

Any other suggestions or advise?

Thanks!

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30809
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: How to query SQL from Joomla 1.7?

Post by Per Yngve Berg » Wed Nov 30, 2011 7:08 pm

So the data is stored in MS SQL Server.

The web server must have the MS SQL Server client installed in php.

Use the php library for MS SQL Server to access that database.

http://no.php.net/manual/en/book.mssql.php

whyknott
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Tue Nov 29, 2011 8:22 pm

Re: How to query SQL from Joomla 1.7?

Post by whyknott » Wed Nov 30, 2011 7:25 pm

Hi Per Yngve Berg-

Yes the data I need to showcase on the web page is stored in an MS SQL server. So a query needs assembled using the PHP execute ms sql function, right?

Here is the code that my colleague came up with does it look right? If it does, then how do I implement into Joomla 1.7? In other words, what code goes in the index.php file and how do the files work together such as the file structure for implementing such code??

Here's the documentation page:
http://php.net/manual/en/function.mssql-execute.php

/* Total Statistics Query */

<?php
$host = my_ip_address
$user = myusername
$pass = mypassword
$database = mydatabase
$conn = mssql_connect($host, $user, $pass);
mssql_select_db($database, $conn);

$stmt = mssql_init('usp_getsavingsinfo');
$result = mssql_execute($stmt);
mssql_free_statement($stmt);
?>

Thanks for everyone's help so far. So glad I posted my question!

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30809
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: How to query SQL from Joomla 1.7?

Post by Per Yngve Berg » Wed Nov 30, 2011 7:32 pm


whyknott
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Tue Nov 29, 2011 8:22 pm

Re: How to query SQL from Joomla 1.7?

Post by whyknott » Wed Nov 30, 2011 7:50 pm

Per Yngve Berg -

Thanks for the link so I guess I need to create a custom component within Joomla then assign the new component to the area of my home page where I want it to display, right?

Looks kinda intricate but I will try and follow the steps from the link you supplied in order to get my data from the MS SQL server to display on the page dynamically.

Any other feedback before I begin? I scanned over the link you provided it seems as though close attention needs to be followed when setting up the file structuring.

Thanks again!


Locked

Return to “Joomla! 2.5 Coding”