U
U
uuuu2021-06-17 22:39:13
PHP
uuuu, 2021-06-17 22:39:13

How to connect once to the database?

Is it possible to connect once to the mysql database and then make any queries with this database? Now it turns out that in each .php document it is necessary to connect to the database again and again every time.

Answer the question

In order to leave comments, you need to log in

18 answer(s)
D
DevMan, 2021-06-17
@uuuu

in classic php this is impossible: the script dies at the end of its work with all data and connections.
you can make a permanently living service or server, but why? there is nothing critical in "each time to connect to the database again and again" if you do not have a highload thread.
and in order not to copy-paste the connection code from a file to a file, includes and / or a single entry point are invented.

V
Vitsliputsli, 2021-06-18
@Vitsliputsli

Is it possible to connect once to the mysql database and then make any queries with this database?

Can.
If ".php documents" are files used by a single php process, then that's the way it should be. If you need different processes to use the same database connection, then this is not a question for php, but for who will maintain this connection and fumble for php processes. There is a persistent connection on the DBMS side, but it is better not to use it, because it doesn't always work correctly. There are all sorts of ProxySQL that can organize this, this is the best option.

S
sphinks, 2012-07-02
@sphinks

Ubuntu is nice and friendly.

S
scream4ik, 2012-07-02
@scream4ik

Debian

L
Lev Lybin, 2012-07-02
@lybin

Regardless of what you do, I recommend Archlinux.

M
Maxim Kuzovlev, 2012-07-02
@KY3EH

Depends on habit. Some people are comfortable with Debian-based distributions. (Debian, Linux Mint Debian, Ubuntu) /
Someone based on RedHat (Fedora, CentOS...)
Someone likes to "build for themselves" and takes Gentoo ... You can also Calculate ...
That is, you can list for a very long time. You can try to install one or another distribution kit in a virtual machine and watch ... In general, everything is individual ...

P
Peter Adrianov, 2012-07-02
@adrianov

Linux Mint is a very user-friendly interface and suitable packages for Ubuntu.

@
@sledopit, 2012-07-02
_

Pick me, pick me (:

E
eydemidov, 2012-07-02
@eydemidov

I would suggest looking at Linux Mint. The same ubuntu, but prettier and without sudden ingenious solutions a la Unity.

C
Cryptochild, 2012-07-02
@Cryptochild

Favorite distribution of a familiar Linux neighbor. Or Ubunutu (in variations)

P
pentarh, 2012-07-03
@pentarh

Fedora or OpenSUSE. IMHO, the most doped ones. I have never been lucky with bubunta) as a rule, on major updates. Fake whistles are certainly buzzing, but stability is more important to me personally.

E
eaa, 2012-07-02
@eaa

Read here - there is a comparison of different options.

V
VBart, 2012-07-02
@VBart

Gentoo of course. The most convenient and least time-consuming distribution to maintain.

K
KawaiDesu, 2012-07-03
@KawaiDesu

Xubuntu. If necessary, I will write why.

N
Nickel3000, 2012-07-02
@Nickel3000

The question is similar to “what fruit would you recommend, apples or oranges?”. To each his own, but one piece of advice - try the most popular ones, and then choose the one that suits you. Of course, it is better to start with a simple one and with a large community, like Ubuntu, it will be easier to get used to.

N
Nepofigist, 2012-07-02
@Nepofigist

Ubuntu.

R
Roler, 2012-07-20
@Roler

Ubuntu or derivatives.
Less hemorrhoids with installation and initial configuration, more prettiness, let's say briefly =)
+ huge community, a lot of faq and advice

T
Taras M, 2016-05-12
@kalduntus

Fedora RF remix 23
is IT, fast, responsive, and beautiful

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question