T
T
TCloud2018-09-21 02:56:33
PHP
TCloud, 2018-09-21 02:56:33

How to close db connections in time in PHP?

Good day to all.
Tell me how to close and open a database connection in time using PHP.
Let's make sure that there is no influx of information that the connection opening/closing functions will be mysql_connect( ) / mysql_close( ).
Unfortunately, I'm new to PHP, so I get this taftology:

function (  ){
mysql_connect ( ... );
// тело функции, например какой то запрос ...
mysql_close( ... );
}

How to open and close connections in time when executing one request and at the same time not prescribe such taftology every time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2018-09-21
@OTCloud

if in a simple way - at the beginning of the script they opened it, at the end of the script they closed it.

A
Andrey Yumashev, 2018-09-21
@skazkin

Create your own view function

function doQuery () {
    mysql_connect ( ... );
    mysql_query ( ... );
    mysql_close( ... );
}

I would not recommend making such a solution, because on something more or less serious it can lead to unnecessary load on the server. It is better to try to build an architecture in such a way that, within the framework of one connection, it is as efficient as possible to drive data into a connection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question