RE: [PHP] connecting to mysql db
Place the code in a file ( ie; dbcon.php ) and include that file in any page which may need it using an include statement: include(dbcon.php); Randy -Original Message- From: Iggy [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 7:50 AM To: [EMAIL PROTECTED] Subject: [PHP] connecting to mysql db hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code ?php $link = mysql_connect(localhost, , ) or die(Could not connect: . mysql_error()); print (Connected successfully); mysql_select_db(test) or die(Could not select database: . mysql_error()); ? thanx iggy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] connecting to mysql db
This really doesn't explain me much. I mean the difference between having that code on every page or calling it from an external page doesn't tell me if it is realy necessary to do it all the time. I guess I am looking for more generic explanation of the whole process rather than what you said. However I appreciate it much, since it seems to be much better coding practice Iggy Randy Rankin [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Place the code in a file ( ie; dbcon.php ) and include that file in any page which may need it using an include statement: include(dbcon.php); Randy -Original Message- From: Iggy [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 7:50 AM To: [EMAIL PROTECTED] Subject: [PHP] connecting to mysql db hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code ?php $link = mysql_connect(localhost, , ) or die(Could not connect: . mysql_error()); print (Connected successfully); mysql_select_db(test) or die(Could not select database: . mysql_error()); ? thanx iggy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] connecting to mysql db
No dude. Create a file called whatever.inc that includes the code that you are using to connect to the db. In every php script ,that needs this connection to the db, you simply put: ?php include(whatever.inc); ? Mirco Ellis I-Soft Solutions e-mail: [EMAIL PROTECTED] Tel: +27414847161 -Original Message- From: Iggy [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 15:50 To: [EMAIL PROTECTED] Subject: [PHP] connecting to mysql db hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code ?php $link = mysql_connect(localhost, , ) or die(Could not connect: . mysql_error()); print (Connected successfully); mysql_select_db(test) or die(Could not select database: . mysql_error()); ? thanx iggy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] connecting to mysql db
Hi Iggy, I mean the difference between having that code on every page or calling it from an external page doesn't tell me if it is realy necessary to do it all the time. Yes, you do have to connect to the database in every script that needs to access it. Usually this is done at the start of the script, along with any calls to session_start() and other global stuff. For convenience and ease of maintenance, however, it makes good sense to write a separate file that does nothing but connect to the database. This separate file then needs to be attached to the running script via include(), at any point before the first call to the database. HTH Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] connecting to mysql db
This is the only way I know and probably the safest. This way you know there is connectivity because it is loaded rigth at the beginning. Mirco Ellis I-Soft Solutions e-mail: [EMAIL PROTECTED] Tel: +27414847161 -Original Message- From: Igor Frankovic [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 16:03 To: [EMAIL PROTECTED] Subject: RE: [PHP] connecting to mysql db But is it always necessary to do this or can you open this connection once and have it open throughout the next few pages (or as needed) and then close it? -Original Message- From: Mirco Ellis [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 8:00 AM To: 'Iggy' Cc: Php-General (E-mail) Subject: RE: [PHP] connecting to mysql db No dude. Create a file called whatever.inc that includes the code that you are using to connect to the db. In every php script ,that needs this connection to the db, you simply put: ?php include(whatever.inc); ? Mirco Ellis I-Soft Solutions e-mail: [EMAIL PROTECTED] Tel: +27414847161 -Original Message- From: Iggy [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 15:50 To: [EMAIL PROTECTED] Subject: [PHP] connecting to mysql db hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code ?php $link = mysql_connect(localhost, , ) or die(Could not connect: . mysql_error()); print (Connected successfully); mysql_select_db(test) or die(Could not select database: . mysql_error()); ? thanx iggy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] connecting to mysql db
leaving the connection open creates security questions, and also leaves resources open, what if a user closes his browser window, how do you know to close the connection? if you really want to make it simple, you can edit your php.ini to have the username and password as default in there, but again, this can be a security risk. i'm afraid the best way is to include connection code on every page... -- skate - fatcuban.com Iggy [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This really doesn't explain me much. I mean the difference between having that code on every page or calling it from an external page doesn't tell me if it is realy necessary to do it all the time. I guess I am looking for more generic explanation of the whole process rather than what you said. However I appreciate it much, since it seems to be much better coding practice Iggy Randy Rankin [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Place the code in a file ( ie; dbcon.php ) and include that file in any page which may need it using an include statement: include(dbcon.php); Randy -Original Message- From: Iggy [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 7:50 AM To: [EMAIL PROTECTED] Subject: [PHP] connecting to mysql db hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code ?php $link = mysql_connect(localhost, , ) or die(Could not connect: . mysql_error()); print (Connected successfully); mysql_select_db(test) or die(Could not select database: . mysql_error()); ? thanx iggy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] connecting to mysql db
At 14:49 25-3-2003, you wrote: hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code ?php $link = mysql_connect(localhost, , ) or die(Could not connect: . mysql_error()); print (Connected successfully); mysql_select_db(test) or die(Could not select database: . mysql_error()); ? maybe you are looking for: http://www.php.net/manual/en/function.mysql-pconnect.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php