maba Posted November 28, 2012 Share Posted November 28, 2012 Hi, is it possible achieve this (http://engaging.net/docs/external-entries) with PW? I have to read (only read for now) from an external database and create some pages with a minimal user interaction (ajax). Thanks, Marco Link to comment Share on other sites More sharing options...
diogo Posted November 28, 2012 Share Posted November 28, 2012 There isn't a tool like this in PW. But honestly using it doesn't seem much easier than doing normal mysql queries... Is there any advantage? Link to comment Share on other sites More sharing options...
maba Posted November 28, 2012 Author Share Posted November 28, 2012 You are right. But which is the best practice to use mysql for a second connection? Use mysql_connect() in all interested templates? Link to comment Share on other sites More sharing options...
ryan Posted November 28, 2012 Share Posted November 28, 2012 If you want to access another MySQL connection, you have any of the native PHP options (mysqli, PDO) available at your disposal. You could also use ProcessWire's Database class (derived from mysqli) to start another connection. Lastly, you could include some other library like to use ActiveRecord from Code Igniter, for example. Personally, I would just keep it simple and use Database, mysqli or PDO. But I would not use mysql_connect, because the old mysql driver in PHP is deprecated... you can use it, but your code might break in some future version of PHP. If you want to use PW's Database class, here's an example of how you'd do it: $mydb = new Database('localhost', 'user', 'pass', 'db_name'); $result = $mydb->query("SELECT * FROM some_table"); while($row = $result->fetch_assoc()) { print_r($row); } See PHP's mysqli functions, as the Database class essentially is identical to mysqli with some extra PW-specific stuff thrown in that won't matter if you are interacting with a non-PW database. To use native mysqli, you'd just replace "new Database(...)" with "new mysqli(...)". 4 Link to comment Share on other sites More sharing options...
maba Posted November 28, 2012 Author Share Posted November 28, 2012 Thanks fot the answer. Now I imagine that this solution can be used also for the multisite question.. Yes.. I have made the wrong example telling about mysql_connect Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now