Answer the question
In order to leave comments, you need to log in
How can I speed up the database connection script?
Salut, guys, tell me if it's possible to rewrite the script better, if I'm a krivoruk.
I watched the script execution speed through
$start = microtime(true);
//code_here
echo (microtime(true) - $start).' сек.';
$db = new Database('localhost','devbase','developer','pass');
class Database {
private $host;
private $dbName;
private $user;
private $pass;
private $DBH;
function __construct($host,$dbname,$user,$pass) {
$this->host = $host;
$this->dbname = $dbname;
$this->user = $user;
$this->pass = $pass;
$this->DBH = new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->user,$this->pass);
}
function delete($tableName, $conditions, $priority = '') {
$query = $this->DBH->prepare("DELETE $priority FROM $tableName WHERE $conditions");
return $result = $query->execute();
$query = null;
$this->DBH = null;
}
}
Answer the question
In order to leave comments, you need to log in
Try changing localhost to 127.0.0.1 the connection first tries to resolve the name.
The time to create a connection to the database server on the local machine is 240ms, which is not normal.
Is there something wrong with the server perhaps?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question