Tag Archives: php

PHP: DBConfig Class

This is a short note, my own bicycle:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
class DBConfig{
    private $hostname;
    private $port;
    private $username;
    private $password;
    private $dbname;
   
    public function &__get($property) {
        if(property_exists($this, $property)){
            return $this->$property;
        }
    }

    public function __set($property, $value) {
        if(property_exists($this, $property)){
            $this->$property = $value;
        }
    }
}
?>

How to use:

1
2
3
4
5
6
    $dbconf = new DBConfig();
    $dbconf->hostname = "127.0.0.1";
    $dbconf->port = 6432;
    $dbconf->username = "user_ro";
    $dbconf->password = "user_ro_pass";
    $dbconf->dbname = "test_db";

Then you could use it where do you want:
pgsql:

1
$dbconn = pg_connect("host = $dbconf->hostname port = $dbconf->port, dbname = $dbconf->dbname, user = $dbconf->username, password = $dbconf->password options='--client_encoding=UTF8'");

nginx: file not found

I have nginx + php but got message «File not found»,
this is a part of my config where i set proxy for php-fpm:

    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/test$fastcgi_script_name;
        include fastcgi_params;
    }

Fix is simple as a piece of cake:

    location ~ .php$ {
        root /var/www/test;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/test$fastcgi_script_name;
        include fastcgi_params;
    }

php: default charset

Was the need to print the page the result of the script. In the system console script gave some data with dates of the form:

Fri Jan 15 08:14.

When is my script displays them on the page, then the conclusion has already been as follows:

Пят Янв 15 08:14, while my page was encoding cp1251, and the output from the script came in KOI8-R.

Solution was simple.

nano php.ini

default_charset = «CP1251 »