RE: MySQL Session

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

welcome to php :)

in general you can use an include at the beginning of each page

<?php
include('database_conn.php' ) ;

$query = 'select * from table'
$result = ($query, $link)



?>



-----Original Message-----
From: Morten Twellmann [mailto:twellmann@c.dk]
Sent: 27 July 2003 13:01
To: php-db@lists.php.net
Subject:  MySQL Session


I have just recently entered the world of PHP and MySQL. I'm used to code in
ASP with Access databases and since I am not very familiar with PHP, I have
run into a problem, which is probably quite easy to solve:

Connecting to the database requires a couple lines of code, which I would
rather not have to write on every single page, which needs the database
connection.
($link = mysql_connect("host", "username", "password")
   or die("Could not connect : " . mysql_error());
  mysql_select_db("dbname") or die("Could not select database.");)

In ASP this is easy to solve, since I would just create a "global.asa" and
on the Application_OnStart procedure, I would create the global database
connection and then reference to that variable on each of the individual
pages.

Now, in PHP I do not seem to be able to create a "global.asa" or anything
similar. It does not even seem to have an "Application" object, which I can
refer to on any page.

Can anyone tell me how I can connect to the MySQL database from some kind of
a global page, being activated no matter which page the user starts on and
where I only need to write the different SQL statements in the individual
pages.
(In ASP I could do the following on the individual page:
Set RS = Application("conn").Execute("SELECT * FROM database")

Thank you.

Morten



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux