I want to open new connection DB in my snippet, but it can’t
The modx table won’t work because the connection is wrong.
How to solve this problem?
thank you
-
☆ A M B ☆
- 24,524 Posts
Open the connection when you need to access the external database, make your query and save the results, then close the connection. The script should now revert to the original (MODx) connection to the MODx database, and you will have the data you retrieved from the external database.
-
☆ A M B ☆
- 24,524 Posts
Hey, us elven Rangers have to stick together!
lol
Hey it didn’t work again.
Sorry it’s my bad.
this is the error message
« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« Execution of a query to the database failed - Table ’resepkita.resep_atrating_grpname’ doesn’t exist »
SQL: SELECT rating_id as ’params’, rating as ’nbStars’, lastIP as ’atrTpl’, nbIP, voteDate as ’endDate’ FROM resep_atRating_grpName WHERE id = ’1’
[Copy SQL to ClipBoard]
-
☆ A M B ☆
- 24,524 Posts
-
☆ A M B ☆
- 24,524 Posts
um... why are you closing the connection before you use it?
You should get the connection variables and use them
include_once $modx->config['base_path'].'/ResepKita/common/lib/php/configuration.php';
$newconn = mysql_connect($MY_CONF["mysql_host"],$MY_CONF["mysql_user_name"],$MY_CONF["mysql_user_password"]);
mysql_select_db($MY_CONF["mysql_database_name"], $newconn);
// do your database queries here
$myresults = mysql_query('blah...', $newconn);
mysql_close($newconn);
do whatever to $myresults now.
http://us.php.net/manual/en/ref.mysql.php
I just test the connection, so I will use it when the connection is working.
I’ll try that.
EDITED
Yes it is works, thanks a lot sotwell.
Sorry for the long time to response this post, I was sick yesterday.