473,326 Members | 2,815 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,326 software developers and data experts.

How often do I need to connect to MySQL database?

Hi,
At present at the top of each of my php pages I reconnect to my
database

mysql_connect(...);

is that actually necessary/good practice. Isn't there something about
persistent connections.

--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305

Mar 13 '07 #1
7 2813
At present at the top of each of my php pages I reconnect to my
database

mysql_connect(...);

is that actually necessary/good practice. Isn't there something about
persistent connections.
instead of connecting on each php page you should put your connection
details in a seperate file and use require_once() to call it.

This will make it easier to change and also will defend against connecting
to the database more than once accidentally.
Mar 13 '07 #2
zzapper wrote:
Hi,
At present at the top of each of my php pages I reconnect to my
database

mysql_connect(...);

is that actually necessary/good practice. Isn't there something about
persistent connections.
yes, try pconnect as in mysql_pconnect()

But I wouldn't expect that will seriously speed up your scripts.
If you want to investigate: www.php.net and type mysql_pconnect into the
searchbox.

Regards,
Erwin Moller
>
--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305
Mar 13 '07 #3
On Mar 13, 8:43 pm, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
zzapperwrote:
Hi,
At present at the top of each of my php pages I reconnect to my
database
mysql_connect(...);
is that actually necessary/good practice. Isn't there something about
persistent connections.

yes, try pconnect as in mysql_pconnect()
Hi
thnx 4 quick replies
Yes I actually use an include for the connection.
I assume mysql_pconnect obviates the need for require_once?

--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305
Mar 13 '07 #4
>mysql_connect(...);
>>
is that actually necessary/good practice. Isn't there something about
persistent connections.

yes, try pconnect as in mysql_pconnect()

But I wouldn't expect that will seriously speed up your scripts.
I would expect mysql_pconnect() to seriously overload your MySQL
server with idle connections unless you carefully tune it.
>If you want to investigate: www.php.net and type mysql_pconnect into the
searchbox.
Mar 13 '07 #5
zzapper wrote:
Hi,
At present at the top of each of my php pages I reconnect to my
database

mysql_connect(...);

is that actually necessary/good practice. Isn't there something about
persistent connections.

--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305
You do NOT want to use mysql_pconnect(). This does create persistent
connections - but now these connections will be tying up system
resources as long as MySQL is running. And you will still have to issue
mysql_pconnect() at the start of each page. And you will have to keep
at least as many persistent connections available as your peak demand
requires.

mysql_pconnect() might be applicable if you were running 10K or more
connections per second - but for your normal website it will hurt you
more than it will help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 14 '07 #6
On Mar 14, 3:38 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
zzapperwrote:
Hi,
At present at the top of each of my php pages I reconnect to my
database
mysql_connect(...);
is that actually necessary/good practice. Isn't there something about
persistent connections.
--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305

You do NOT want to use mysql_pconnect(). This does create persistent
Hi
So is it normal to connect to the db once per page, the reason I ask
this is that I'm getting "you gave exceeded the maximum number of
connections per hour (400)" from my webserver, but I'm currently to
only one accessing it!
Does "require once" only prevent me from connecting more than once per
page?

--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305
Mar 14 '07 #7
zzapper wrote:
On Mar 14, 3:38 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>zzapperwrote:
>>Hi,
At present at the top of each of my php pages I reconnect to my
database
mysql_connect(...);
is that actually necessary/good practice. Isn't there something about
persistent connections.
--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305
You do NOT want to use mysql_pconnect(). This does create persistent

Hi
So is it normal to connect to the db once per page, the reason I ask
this is that I'm getting "you gave exceeded the maximum number of
connections per hour (400)" from my webserver, but I'm currently to
only one accessing it!
Does "require once" only prevent me from connecting more than once per
page?

--
zzapper
Best of VimTips
http://www.vim.org/tips/tip.php?tip_id=305

No, every page must make its own connection to the server. At the end
of the page, that connection will be closed by the PHP cleanup if you
don't do it yourself.

What's not clear is if this is your server or a shared host. If this is
your own server, you need to change your MySQL setup (try
comp.databases.mysql for help). If this is a hosted server, you need to
talk to your host.

But if I were in this position on a hosted server, I'd find another
host. 400 connections per hour is nothing. And if that's what they
limit you to, chances are they're overselling their servers.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 14 '07 #8

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

Similar topics

1
by: Jordy | last post by:
Environment: Sun servers running solaris 2.8 Php 4.3.6 Apache 1.3.29 Mysql 4.1.1 phpMyAdmin 2.6.0-alpha1 phpAds 2.0 PhpMyadmin and phpAds don't succeed to connect the MySql database when
5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
0
by: Bill Hernandez | last post by:
Hi, I've been writing software on the mac since 1987, but am brand new at unix/php/mysql, and that's where I'm headed so I'm reading everything I can get my hands on, but like anything else...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: news.telia.net | last post by:
Hi! I have a question. I have installed php and mysql on an apache-server on windows and I can't connect to the server. I tried to create a database (since I am trying to learn howto). My...
4
by: d3vkit | last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was...
6
by: markodilore | last post by:
Hey Guys, you helped me once when I tryied to create a database : "Access denied for user ''@'localhost' ". On my Mac OS 10.4, I had no problem creating database and modifying it from the terminal....
11
by: bthalapathi | last post by:
I have written a script to connect the mysql db #!/usr/bin/perl -w use DBI; #definition of variables $db="MYTEST"; $host="localhost"; $user="root"; $password="rootpass";
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.