Jump to content

Hook throwing an error


szalik.dev

Recommended Posts

Posted

So, it's been a while for me since i've done some plugins, now i'm trying getting back to it.. I've created plugin, for this plugin i've created a hook file, and no matter what i put inside of it, every time it throws error 

Quote

ParseError thrown with message "syntax error, unexpected '$variable' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST)"

that's how my hook file looks like:

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class hook28 extends _HOOK_CLASS_
{

$variable = "value";

}

 

Posted
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class hook28 extends _HOOK_CLASS_
{

public $tvc_conn = \IPS\Db::i('tvcdb', array('sql_host' => 'test', 'sql_user' => 'user', 'sql_pass' => 'pass', 'sql_database' => 'dbname'));

}
Posted

If you are trying to achieve a connection to a DB, other than your community DB, you wouldn't overload the DB class...

Simply initialize the connection / create the object when you need it. Don't try to have it always persistent. 

Posted

I'm thinking that I don't get something. But here's what I did, I've created a public function inside hook class called dbconn, I've set up db connection there, website is not throwing any errors but I'm not sure if it's actually working..

Posted
8 hours ago, ~Jakso.` said:

I'm thinking that I don't get something. But here's what I did, I've created a public function inside hook class called dbconn, I've set up db connection there, website is not throwing any errors but I'm not sure if it's actually working..

If I understand what you're trying to do, it won't work like you expect it will. Adding in a public method to IPS\Db with your remote connection details there. Not going to work as you expect.. 

Don't hook into IPS\Db, hook into where you want the data and simply consolidate a method in you app / plugin that returns a DB instance connected to your remote  DB. Look at the docs I linked above that show how to set up the DB instance to an external DB as it is intended.

Posted

So why not just use a second DB instance?  

	/**
	 * Get instance
	 *
	 * @param	mixed	$identifier			Identifier
	 * @param	array	$connectionSettings	Connection settings (use when initiating a new connection)
	 * @return	\IPS\Db
	 */
	public static function i( $identifier=NULL, $connectionSettings=array() )

Use a new identifier and pass the connection settings as second parameter

Posted

I'm doing so. I've set up a public function called dbconn where I've put 

	$tvc_conn = \IPS\Db::i('tvcdb', array('sql_host' => 'test', 'sql_user' => 'user', 'sql_pass' => 'pass', 'sql_database' => 'dbname'));
	return $tvc_conn;
	

It should work, yes?

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...