Hi,

I have the following:

$_host = $DHOY_CONFIG['db'][$connection_name]['host'];

			$_name = $DHOY_CONFIG['db'][$connection_name]['name'];

			$_port = $DHOY_CONFIG['db'][$connection_name]['port'];

			$_user = $DHOY_CONFIG['db'][$connection_name]['user'];

			$_pass = $DHOY_CONFIG['db'][$connection_name]['pass'];



			$dsn = "mysql://$_user:$_pass@$_host:$_port/$_name?new_link=true";

			

			print "dsn is $dsn";



			if ($dsn != 'mysql://:@:/?new_link=true') {

				$db_connection[$connection_name] = DB::connect($dsn);



				if (!DB::isError($db_connection[$connection_name])) {

					return $db_connection[$connection_name];

				} else {

					trigger_error("General system error ID: 00002 - DSN empty", E_USER_ERROR);

the DSN looks fine: mysql://loquo_r:r@127.0.0.1:3306/loquo_test?new_link=true

getMessage() gives me a "Connect Failed" error, I have been looking over the internet, but I haven't found any solution and the message isn't very clear

I have tried to connect from the cmd and it works with "mysql -uloquo_r -pr -Dloquo_test"

I don't if there is something trivial I am missing or what.

any idea?

Thanks in advance.

Un saludo y muchas gracias.

hello ,

are u simply tring to connect to mysql or you need to do something else?
Im asking becouse if it is simple connect you can do like this.

<?php

$dbHost = “localhost”;
$user = “userName”;
$pass = “passw”;
$dbName=”your_db_name”;

$conn = mysql_connect($dbHost, $user, $pass, $dbName ) or die (“Connection error ” . mysql_error());

// aqui comprobar la connexion (optional)

if($conn) {

echo”Your db name is:  $dbName ” ;

}else
{
echo”cant connect ”;
}


?>

and then you can get the connection data where you want.

saludos

Have you tried without ?new_link=true ?

Yes, I have tried without success

hello ,

are u simply tring to connect to mysql or you need to do something else?
Im asking becouse if it is simple connect you can do like this.

<?php

$dbHost = “localhost”;
$user = “userName”;
$pass = “passw”;
$dbName=”your_db_name”;

$conn = mysql_connect($dbHost, $user, $pass, $dbName ) or die (“Connection error ” . mysql_error());

// aqui comprobar la connexion (optional)

if($conn) {

echo”Your db name is:  $dbName ” ;

}else
{
echo”cant connect ”;
}


?>

and then you can get the connection data where you want.

saludos

what's the difference between the two functions to connect to the database?
I'm going to try it.

I have tried, and now I'm getting the following:

Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\loquotest\shared\source\classes\biz\ManagerBase.php on line 47

Fatal error: Call to a member function on a non-object in C:\loquotest\shared\source\classes\biz\ManagerBase.php on line 338

Hello,
I think it is your server’s problem, can you send me the PHP server data?

regards

can you post your ManagerBase.php?
thanks

Sorry I can not do it, I do not have an access to php. If I can help in other things so ask please.

Regards

can you post your ManagerBase.php?
thanks

<?php

/**

 *

 * 	Manager Base class

 *

 */

 

 

// TODO: Get rid of this define once Smarty Calc is in place

// Number of seconds in a day

define('DHOY_ONE_DAY',   		'86400');



define('BROWSE_JOIN_CONDITION', 'join_condition');



require_once 'PEAR.php';

require_once 'DB.php';

require_once 'config/settings.php';



// A poor's man singleton

if (!isset($db_connection))

{

	$db_connection = array();

}



class ManagerBase

{



	function getDBConnection($connection_name = DHOY_DB_CONN_CITY_READ) {

		global $db_connection;

		global $DHOY_CONFIG;



		if (isset($db_connection[$connection_name])) {

			return $db_connection[$connection_name];

		} else if (!isset($DHOY_CONFIG['db'][$connection_name])) {

			trigger_error("General system error ID: 00001 - Undefined db: " . $connection_name, E_USER_ERROR);

		} else {

			$_host = $DHOY_CONFIG['db'][$connection_name]['host'];

			$_name = $DHOY_CONFIG['db'][$connection_name]['name'];

			$_port = $DHOY_CONFIG['db'][$connection_name]['port'];

			$_user = $DHOY_CONFIG['db'][$connection_name]['user'];

			$_pass = $DHOY_CONFIG['db'][$connection_name]['pass'];



			$dsn = "mysql://$_user:$_pass@$_host:$_port/$_name?new_link=true";

			

			print "dsn is $dsn";



			if ($dsn != 'mysql://:@:/?new_link=true') {

				$db_connection[$connection_name] = DB::connect($dsn);



				if (!DB::isError($db_connection[$connection_name])) {

					return $db_connection[$connection_name];

				} else {

					trigger_error("General system error ID: 00002 - DSN empty", E_USER_ERROR);

				}

			} else {

				trigger_error("General system error ID: 00002 - DSN empty", E_USER_ERROR);

			}

		}



		return $db_connection[$connection_name];

	}



	function freeDBConnection($connection_name = DHOY_DB_CONN_ALL)

	{

		global $db_connection;



		if ($connection_name == DHOY_DB_CONN_ALL) {

			foreach ($db_connection as $key => $connection) {

				if (!DB::isError($db_connection[$key])) {

					$db_connection[$key]->disconnect();

					unset($db_connection[$key]);

				}

			}

		} else {

			if (isset($db_connection[$connection_name]) 

				&& !DB::isError($db_connection[$connection_name])) {

				$db_connection[$connection_name]->disconnect();

				unset($db_connection[$connection_name]);

			}

		}

	}

	

	function nextGenId($table) {

		$db = ManagerBase::getDBConnection(DHOY_DB_CONN_CITY_WRITE);

		return $db->nextId($table);

	}





	/**

	* 	browse (single table)

	*

	*	@table_name 	

	*	@param $values (associative array of values to fetch)

	*		// NOTE: The special key BROWSE_JOIN_CONDITION is not a value to fetch but a join condition

	*		// TODO fix later

	*

	*	@param $and (associative array of operator and values to discriminate on)

	*	@param $or (associative array of values and operators to discriminate on)

	*

	*		e.g.

	*		['age']['val'] 	= '50'

	*		['age']['op'] 	= '>'

	*

	*		Notes

	*			operator defaults to '='

	*			if operator is LIKE, value should include the %

	*

	*	@param $order (ordering of the result set)

	*

	*		e.g. $order = array( 

	*							POST_CREATION_DATE=>"DESC"

	*							);

	*

	*	@param $group_by (ordering of the result set)

	*

	*		e.g. $group_by = 'post.id'

	*

	*	@limit (limits the amount of rows returned -defaults to 500)

	*

	* @access public

	*/

	function &browse(	$table_name,

						$values,

						$and, 

						$or,

						$order 		= null, 

						$limit		= 500,

						$group_by	= null,

						$read_only_conn = false)

	{

		global $DHOY_CONFIG;

		$column_list = null;

		$where_clause = null;

		$order_by = null;



		$sql_cache = true;



		$db = ManagerBase::getDBConnection($read_only_conn ? DHOY_DB_CONN_CITY_READ : DHOY_DB_CONN_CITY_WRITE);



		// select colums

		foreach ($values as $key=>$value)

		{

			// TODO Fix this nasty little kludge !!!!

			// Make sure that it isn't a join condition

			if (!empty($value))

			{

				continue;

			}



			if (isset($column_list))

			{

			 	$column_list = $column_list . ",";

			}



			$column_list = $column_list . $key;

		}



		// AND clause

		if (isset($and))

		{

			$first = true;

			foreach ($and as $and_elem)

			{

				if (!$first)

				{

				 	$where_clause = $where_clause . " AND ";

				}



				$column = $and_elem['col'];

				$operator = empty($and_elem['op']) ? '=' : $and_elem['op'];



				// Don't quote value for 'is' or 'is not' operators

				if (stristr($operator, 'is'))

				{

					$value = $and_elem['val'];

				}

				else

				{

					$value = $db->quote((string)$and_elem['val']);

				}

		

				if (!strcasecmp($operator, "against"))

				{

					// If searching not SQL_CACHE

					$sql_cache = false;



					// Important !!! 

					// Converting to boolean search



					$operator = ' AGAINST ';



					$query_terms = _explodeBooleanSearch(DHOY_PostSearchManager::_cleanString($and_elem['val']));



					$value = '('. $db->quote((string)$query_terms). ' IN BOOLEAN MODE)';

				}

				else if (!strcasecmp($operator, "in"))

				{

					$operator = ' IN ';



					$in_clause = null;



					foreach ($and_elem['val'] as $key=>$val)

					{

						if (!isset($in_clause))

						{

							$in_clause = '('. $db->quote((string)$key);

						}

						else

						{

							$in_clause = $in_clause. ','. $db->quote((string)$key);

						}

					}



					$in_clause = $in_clause.')';

					

					$value = $in_clause;

				}



				$where_clause = "$where_clause$column$operator$value";

				$first = false;

			}

		}



		// OR values

		if (isset($or))

		{

			// Important! we need to AND the OR branch of the query tree

			if (isset($and))

			{

			 	$where_clause = $where_clause . " AND (";

			}



			$first = true;

			foreach ($or as $or_elem)

			{

				if (!$first)

				{

				 	$where_clause = $where_clause . " OR ";

				}

		

				$column = $or_elem['col'];

				$operator = empty($or_elem['op']) ? '=' : $or_elem['op'];

				

				// Don't quote value for 'is' or 'is not' operators

				if (stristr($operator, 'is'))

				{

					$value = $or_elem['val'];

				}

				else

				{

					$value = $db->quote((string)$or_elem['val']);

				}



				if (!strcasecmp($operator, "like"))

				{

					$operator = " LIKE ";

				}

				else if (!strcasecmp($operator, "against"))

				{

					// Important !!! 

					// Converting to boolean search



					$operator = " AGAINST ";



					$query_terms = _explodeBooleanSearch(DHOY_PostSearchManager::_cleanString($or_elem['val']));

					$value = '('. $db->quote((string)$query_terms). ' IN BOOLEAN MODE)';

				}



				$where_clause = "$where_clause$column$operator$value";

				$first = false;

			}



			if (isset($and))

			{

			 	$where_clause = $where_clause . " )";

			}

		}



		if (isset($order))

		{

			foreach ($order as $key=>$value)

			{

				if (isset($order_by))

				{

				 	$order_by = $order_by . ",";

				}



				$order_by = $order_by . "$key $value";

			}

		}



		// If searching not SQL_CACHE

		if ($sql_cache)

		{

			$sql =	'SELECT SQL_CACHE ';

		}

		else

		{

			$sql =	'SELECT ';

		}



		$sql = $sql . "$column_list FROM $table_name";



		// TODO Fix this nasty little thing

		$join_condition = $values[BROWSE_JOIN_CONDITION];

		if (isset($join_condition))

		{

			$sql = $sql. " $join_condition";

		}



		if (isset($where_clause))

		{

			$sql = $sql . " WHERE $where_clause";

		}



		if (isset($group_by))

		{

			$sql = $sql . " GROUP BY $group_by";

		}



		if (isset($order_by))

		{

			$sql = $sql . " ORDER BY $order_by";

		}



		if (isset($limit))

		{

			$sql = $sql . " LIMIT $limit";

		}

		

		if ( $DHOY_CONFIG['sql_trace'])

		{

			echo "<pre>";

			echo "ManagerBase::Browse SQL <br />\n";

			echo "$sql\n";

			echo "</pre>";

		}



		return $db->query($sql);

	}



	/*

	*

	* Converts timestamp values (PHP time() func) to 

	* mysql format (YYYYMMDDHHMMSS)

	*/

	function timestamp_to_mysql($ts="")

    {  

		if (empty($ts))

		{

			$ts = ManagerBase::makeTimeStamp();

		}



		return strftime("%Y-%m-%d %H:%M:%S", $ts);

    }  



	/*

	*								   

	* Converts mysql formatted values (YYYY-MM-DD-HH-MM-SS) to unix timestamps

	* 

	*/

	function mysql_to_timestamp($string="")

    {  

	    if (strlen($string) == 19) 

	    {

			// Windows doesn't support negative time stamps

			if ( substr($string,0,4) < 1970)

			{

				return 0;

			}



	        $time = mktime(	substr($string,11,2), 	// hour

	        				substr($string,14,2),	// minute

	        				substr($string,17,2),	// second

	               			substr($string,5,2),	// month

	               			substr($string,8,2),	// day

	               			substr($string,0,4)); 	// year



	        return $time;

	    }

		else

		{

			return -1;

		}

    }





	/*

	*	

	* 	Favors GET over POST params

	*/

	function getReqParam($param1, $param2 = '')

	{

		if (empty($param2))

		{

			$ret = $_GET[$param1];

		}

		else

		{

			$ret = $_GET[$param1][$param2];

		}



		if (empty($ret))

		{

			if (empty($param2))

			{

				$ret = $_POST[$param1];

			}

			else

			{

				$ret = $_POST[$param1][$param2];

			}

		}



		return $ret;

	}



}



function _explodeBooleanSearch($val)

{

	$booleanmodeops = array('+', '-', '>', '<', '*', '~');

	$val=str_replace("*", "\\*", $val);	

	if (	$val[0] == '"'

		&&	$val[strlen($val)-1] == '"')

	{

		$query_terms=$val;

	}

	else

	{

		$terms = explode(' ', $val);



		foreach ($terms as $term)

		{

			if (!empty($query_terms))

				$query_terms = $query_terms . ' ';

			$query_terms = $query_terms . (!in_array(substr($term,0,1),$booleanmodeops) ? '+' : '') . $term;

		}

	}



	return $query_terms;

}



?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.