473,219 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

PHP Database Connections

I am new to PHP. I am trying to develop a web site on a development
machine that needs to access data in a mysql database. I have mysql
running on my development machine with a copy of the database. While
developing the app. I can connect to the local version of the database
without problems. Once I upload the database to its host site I need
to change the php scripts that connect to the database to refelect the
appropriate connection associated with the hosting server. Does
anyone know of an efficient way to have my script test for which
location it is on and connect to the appropriate mysql database? Or,
does anyone know of a php script that can handle this
programmatically? Thanks for any time in advance.

A. Cate
Jul 17 '05 #1
2 2103
In article <8b*************************@posting.google.com> ,
ac*****@yahoo.com (A Cate) wrote:
I am new to PHP. I am trying to develop a web site on a development
machine that needs to access data in a mysql database. I have mysql
running on my development machine with a copy of the database. While
developing the app. I can connect to the local version of the database
without problems. Once I upload the database to its host site I need
to change the php scripts that connect to the database to refelect the
appropriate connection associated with the hosting server. Does
anyone know of an efficient way to have my script test for which
location it is on and connect to the appropriate mysql database? Or,
does anyone know of a php script that can handle this
programmatically? Thanks for any time in advance.

A. Cate


I put code in all the relevant scripts to test the URL, which is
different between the development and production systems. All database
access is done in a single class that's included in various files that
need access to the database. That way, I can make one change to the
class and it changes everywhere.

If you don't have programming skills, start reading some basic books on
programming design that discuss larger projects. Such practices like
putting things in header files, reusability, etc. are key to making
something easy to modify and maintain. Since I already have programming
experience, I found the O'Reilly book useful and the PHP Anthology to be
very useful to discuss OOP:

http://www.oreilly.com/catalog/progphp/
http://www.sitepoint.com/books/phpant1/

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #2
This is what I do....

I have a file called db.inc which resides outside the web root on both my
local PC and my web host.

<-- start
$dbhost = "localhost";

if ($_SERVER['SERVER_NAME'] == 'localhost') {
// this is for my PC
$dbusername = "****";
$dbuserpass = "****";
$dbprefix = null;
} else {
// this is for my web host
$dbusername = "********";
$dbuserpass = "********";
$dbprefix = "********";
} // if
<-- end

This sets up different values depending on which location it is being run
from.

$dbprefix is there because on my web host all my database names are prefixed
with my account name.

--
Tony Marston

http://www.tonymarston.net

"A Cate" <ac*****@yahoo.com> wrote in message
news:8b*************************@posting.google.co m...
I am new to PHP. I am trying to develop a web site on a development
machine that needs to access data in a mysql database. I have mysql
running on my development machine with a copy of the database. While
developing the app. I can connect to the local version of the database
without problems. Once I upload the database to its host site I need
to change the php scripts that connect to the database to refelect the
appropriate connection associated with the hosting server. Does
anyone know of an efficient way to have my script test for which
location it is on and connect to the appropriate mysql database? Or,
does anyone know of a php script that can handle this
programmatically? Thanks for any time in advance.

A. Cate

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
4
by: dustin lee | last post by:
Over the years I've gotten out of the habit of explicitly closing file objects (whether for reading or writing) since the right thing always seems to happen auto-magically (e.g. files get written...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
4
by: Sierra | last post by:
Problem: Database connections are not being reused properly. SP_WHO2 shows upwards of 200 connections being created per page request. Most connections exist for 60 seconds then close without...
7
by: Martin | last post by:
Hello Does anyone know if it is possible to use the smo db.Create() method to create a new sql server database with sql server 2005 express? The debugger complains that remote operations are not...
5
by: John | last post by:
I have an ASP.NET 2.0 application developed in VB.net, that accesses an Microsoft Access database. When the database is on the same IIS server all works just fine. BUT when it tried to access the...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
8
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.