PHP Manual
2014-05-16
©
1997-2014
the PHP Documentation Group
- Copyright
- PHP Manual
- Getting Started
- Installation and Configuration
- Language Reference
- Security
- Features
- Function Reference
- Affecting PHP's Behaviour
- Audio Formats Manipulation
- Authentication Services
- Command Line Specific Extensions
- Compression and Archive Extensions
- Credit Card Processing
- Cryptography Extensions
- Database Extensions
- Date and Time Related Extensions
- File System Related Extensions
- Human Language and Character Encoding Support
- Image Processing and Generation
- Mail Related Extensions
- Mathematical Extensions
- Non-Text MIME Output
- Process Control Extensions
- Other Basic Extensions
- Other Services
- Search Engine Extensions
- Server Specific Extensions
- Session Extensions
- Text Processing
- Variable and Type Related Extensions
- Web Services
- Windows Only Extensions
- XML Manipulation
- PHP at the Core: A Hacker's Guide
- Preface
- Memory management
- Working with Variables
- Writing Functions
- Writing Classes
- Working with Resources
- Working with INI settings
- Working with streams
- The "counter" Extension - A Continuing Example
- The PHP 5 build system
- Extension structure
- PDO Driver How-To
- Extension FAQs
- Zend Engine 2 API reference
- Zend Engine 2 Opcodes
- Zend Engine 1
- FAQ — FAQ: Frequently Asked Questions
- Appendices
- History of PHP and Related Projects
- Migrating from PHP 5.5.x to PHP 5.6.x
- Migrating from PHP 5.4.x to PHP 5.5.x
- Migrating from PHP 5.3.x to PHP 5.4.x
- Migrating from PHP 5.2.x to PHP 5.3.x
- Migrating from PHP 5.1.x to PHP 5.2.x
- Migrating from PHP 5.0.x to PHP 5.1.x
- Migrating from PHP 4 to PHP 5.0.x
- Classes and Objects (PHP 4)
- Debugging in PHP
- Configure options
- php.ini directives
- Extension List/Categorization
- List of Function Aliases
- List of Reserved Words
- List of Resource Types
- List of Available Filters
- List of Supported Socket Transports
- PHP type comparison tables
- List of Parser Tokens
- Userland Naming Guide
- About the manual
- Creative Commons Attribution 3.0
- Index listing
- Changelog
Коментарии
A better way to implement singleton desygn pattern and resquest data from a json file to connect to a database mysql. this is from my development project.
<?php
namespace Simulab\Simulab\models\connections;
/**
* Desygn Pattern: Construction: Singleton method.
*/
class SimulabConnection
{
private static $instance = null;
private static $pdo = null;
private function __construct()
{
}
/**
* This method get information like servername, database, user and password from a json file
* All The informations about the database connections.
*/
public static function getJsonData():object{
$filename = '../../config/json/sgbd_informations.json';
if (file_exists($filename)) {
$data = file_get_contents($filename);
$infodb= json_decode($data);
return $infodb;
}else{
return null;
}
}
public static function connect():?\PDO{
if (is_null(self::$instance)) {
self::$instance = new self;
$infodb= self::getJsonData()!=null?self::getJsonData():null;
$server= $infodb->server;
$database= $infodb->database;
$user= $infodb->user;
$password= $infodb->password;
$options= [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
self::$pdo = new \PDO("mysql:host=$server;dbname=$database", $user, $password, $options);
}
return self::$pdo;
}
}