Multiple MySQL database connections.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

highandwild
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Sep 23, 2012 2:47 am

Multiple MySQL database connections.

Postby highandwild » Tue Jan 29, 2013 1:47 pm

I have a three column layout and each column is populated with a list made up of date from
three different tables from a MySQL database.

The code for each column is contained in three seperate files and accessed using include().

Whilst I have got this working before, I have now restructed it and broken it.

So...back to basics, do I:

1. Connect to the database using require_once at the start of the file.
2. Run each query and display the results.
3. Use mysql_free_result to free the result after each query.
4. Use mysql_close to close the connection.

OR

Connect to the database, run the queries and close the connection after each query? All
the code being contained in each of the three files.

OR

Maybe even something else.

Thanks for any advice.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Multiple MySQL database connections.

Postby seandisanti » Fri Feb 08, 2013 1:14 pm

There are several approaches you could try; I believe current consensus would be to make use of PDO http://php.net/pdo the manual has usage suggestions and specifics, and it's a little more than one could reliably explain in a thread.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 16 guests