FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Best PHP way to connect to a DB across multiple pages ?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Best PHP way to connect to a DB across multiple pages ? [message #169477] Tue, 14 September 2010 22:28 Go to previous message
goldtech is currently offline  goldtech
Messages: 5
Registered: September 2010
Karma:
Junior Member
Hi,

I have a basic PHP and MYSQL connection question/reality check.

Let's say I have two pages which rely on getting content from the same
DB. The first page shows all the records from the DB in a brief
tabular format. If the user sees something they are interested in they
click a link in a displayed brief record and go to the second page
which displays a detailed view of the item they clicked on with a
bigger picture and more info.

This is standard, tons of web pages have this format. Both pages pull
info from the same DB using PHP. Let's say I post the primary key of
the item from the brief page and send that key to the detail page. The
detail page uses the key to access the DB again and get more detailed
content for that record.

On both pages I access the DB with:
....
$dbc=@mysqli_connect (...... );
$q = "SELECT.... FROM data";
$r = @mysqli_query($dbc, $q);
....

So I'm make a connection twice, once per each page that uses data from
the DB. Always done it this way. Question: Is this a correct way to
do this?

Thanks,

Lee G.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Reference # in var_dump output?
Next Topic: OOP, classes and databases
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 19:26:30 GMT 2024

Total time taken to generate the page: 0.05416 seconds