× Here you can get community support related to Tag Meta.

MSSQL Queries to Generate Meta Tags

  • quassj
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 10 months ago #630 by quassj
MSSQL Queries to Generate Meta Tags was created by quassj
So far, I am very pleased with the Tag Meta plugin. I purchased the Enterprise version for my company's site and configured as instructed. It does everything promised, but I have been having a little trouble getting the macros to do what I need them to.

The site had a previous designer who created a custom module to display products on screen. The information is indexed in SOLR to speed up user access. Before that it is stored in a MSSQL database. However, the module does make some calls to MSSQL to display certain item attributes like ingredient category.

We have over 70,000 products in our databse, so I don't want to go in and manually enter all the meta tags. Instead, I'd like to use relevant information about the product, like brand or category, to build targeted meta tags dynamically.

My question is, how can I find out what variables exist on the site that I can get through requestvar? Or, how can I create a global variable to store this information publicly through the module?

Alternatively, how would I go about changing the plugin to do MSSQL queries instead of through MySQL?

Please Log in or Create an account to join the conversation.

More
11 years 9 months ago - 11 years 9 months ago #633 by admin
Replied by admin on topic MSSQL Queries to Generate Meta Tags
Ok,
I got your question. As you probably know, last version of Tag Meta supports a lot of macros to extract information (e.g. from the database). You could use this macro together with placeholders to create what you need, and I can support you with this.

The only problem to solve is the current query macros works on MySQL tables, while your data are on MS SQL tables. So we have two ways to solve problem.

If these data are static (i.e. they never change) you could import into a MySQL table, then we query this one.

If these data are dynamic, instead, the best solution is to add a custom macro into Tag Meta to fit your needs. I can help you with this but you should provide me some piece of code related to the current queries (i.e. how the MS SQL queries are performed with PHP code).

I hope this makes sense for you.

Kind regards,
Luigi
Last edit: 11 years 9 months ago by admin.

Please Log in or Create an account to join the conversation.

  • quassj
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 9 months ago #636 by quassj
Replied by quassj on topic MSSQL Queries to Generate Meta Tags
Yeah, this makes sense. The tables are dynamic, as we add new products daily, and will make corrections to old ones as well.

Here's the existing relevant code from the component's view.html.php file. This is for Joomla 1.7.
class productsViewproducts_detail extends JView {


	function MSSQL_single($query) {
		$jconfig = new JConfig();
				
	    $server = $jconfig->mssql_host;
		$username = $jconfig->mssql_username;
		$password = $jconfig->mssql_password;
		$database = $jconfig->mssql_database;	
		
		$sqlconnect = mssql_connect($server, $username, $password) or die("Couldn't connect to MS SQL");
		$sqldb = mssql_select_db($database, $sqlconnect) or die("Couldn't open the Database");

		

		$results = mssql_query($query) or die(mssql_get_last_message());

		$row = mssql_fetch_object($results);

		//$xml = simplexml_load_string($row["xmlResult"]);
		mssql_close($sqlconnect);
		return $row;
	}

	public function getSpecificCategoryID($name)
	{
		$name = str_replace("'", "''", $name);
		$sql = "select * from MainFoodCategories where MainCategoryName='".$name."'";
		return $this->MSSQL_single($sql);
	}

}	

Please Log in or Create an account to join the conversation.

  • quassj
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 9 months ago #637 by quassj
Replied by quassj on topic MSSQL Queries to Generate Meta Tags
Hey Luigi,

Thanks for your response and offer to help with the Tag Meta modifications, but I've already made them and it's working perfectly. Using the code I posted, I replaced the SQL call in the 'tableselect' case in tagmeta.php.

For anyone who need to query MSSQL tables, I'll post the code below. I'm sure there are better ways to do what I did, but this works if in a pinch. Just replace the existing case at approx line 802 with the following.

This also requires that the databse information be defined in the Joomla configuration.php file.
case 'tableselect':
        // $params[0] = table,column,key
        // $params[1] = value
        // table: table name to query (support #__ notation)
        // column: field name to return
        // key: field name to use as selector in where condition
        // value: value to use for comparison in the where condition (WHERE key = value)
        $arg = explode(",", trim($params[0]));
        if (count($arg) == 3)
        {
          $arg = array_map("trim", $arg);
          $value = $params[1];
          if ($value != '')
          {
	    //Original Code
            /* Perform a DB query
            $db = JFactory::getDBO();
            $db->setQuery("SELECT `" . $arg[1] . "` FROM `" . $arg[0] . "` WHERE `" . $arg[2] . "`=" . $db->quote($value));
            $result = $db->loadResult();
            if (isset($result)) { $value = $result; }
            */
            
            //Start of MSSQL query
            $db = JFactory::getDBO();  //Kept for the db quote function to remove special characters
            $query = "SELECT " . $arg[1] . " FROM " . $arg[0] . " WHERE " . $arg[2] . "=" . $db->quote($value);

			
		$jconfig = new JConfig();
		
		// Collects MSSQL server and login information				
		$server = $jconfig->mssql_host;
		$username = $jconfig->mssql_username;
		$password = $jconfig->mssql_password;
		$database = $jconfig->mssql_database;
			
		$sqlconnect = mssql_connect($server, $username, $password) or die("Couldn't connect to MS SQL");
		$sqldb = mssql_select_db($database, $sqlconnect) or die("Couldn't open the Database");
			
		$results = mssql_query($query) or die(mssql_get_last_message());
			
		$row = mssql_fetch_object($results);
			
		mssql_close($sqlconnect);
			
		if(isset($row->$arg[1]))
		{	
			$value = $row->$arg[1];
		}
          }
        }
break;

Please Log in or Create an account to join the conversation.

More
11 years 9 months ago #641 by admin
Replied by admin on topic MSSQL Queries to Generate Meta Tags
Great...
thank you for sharing this code.

Kind regards,
Luigi

Please Log in or Create an account to join the conversation.

Time to create page: 0.111 seconds