本文整理汇总了PHP中MySQLi::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP MySQLi::__construct方法的具体用法?PHP MySQLi::__construct怎么用?PHP MySQLi::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQLi
的用法示例。
在下文中一共展示了MySQLi::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Database constructor (die on error).
*
* {@inheritdoc}
*/
public function __construct($host = null, $username = null, $passwd = null, $dbName = null, $port = null, $socket = null)
{
parent::__construct($host, $username, $passwd, $dbName, $port, $socket);
if (@(!$this->ping())) {
die(PHP_EOL . 'ERROR: Could not connect to the mysql server using the supplied information.' . PHP_EOL);
}
}
示例2: __construct
public function __construct()
{
// inhibit subclassing and instantiation from outside
require_once 'pwd.php';
// read account data (including password)
// initialize the transient associative array
$this->modelTransient = array();
// initialize new or open existing session
session_name($config['session']);
session_start();
// connect to database
try {
parent::__construct($config['host'], $config['user'], $config['pwd'], "ewa");
// check connection
if (mysqli_connect_error()) {
// $this is invalid in case of error
throw new Exception("Keine Verbindung zur Datenbank: " . mysqli_connect_error());
}
} catch (Exception $e) {
// do not show the password in an error message
throw new Exception(str_replace($config['pwd'], "xxx", $e->getMessage()));
}
// define character encoding for connection to database
if (!$this->set_charset(self::charsetDB)) {
throw new Exception("Fehler beim Laden des Zeichensatzes " . self::charsetDB . ": " . $this->error);
}
}
示例3:
function __construct()
{
self::$host = Config::get('db_host');
self::$db = Config::get('db_name');
self::$user = Config::get('db_user');
self::$password = Config::get('db_pass');
parent::__construct(self::$host, self::$user, self::$password, self::$db);
}
示例4: __construct
public function __construct($host, $username, $passwd, $dbname = "", $port, $socket)
{
$host = !isset($host) ? ini_get("mysqli.default_host") : $host;
$username = !isset($username) ? ini_get("mysqli.default_user") : $username;
$passwd = !isset($passwd) ? ini_get("mysqli.default_pw") : $passwd;
$port = !isset($port) ? ini_get("mysqli.default_port") : $port;
$socket = !isset($socket) ? ini_get("mysqli.default_socket") : $socket;
parent::__construct($host, $username, $passwd, $dbname, $port, $socket);
$this->query("SET SESSION sql_mode = ''");
}
示例5: __construct
public function __construct()
{
require '/home/sites/aaa.to' . '/instagram_dbaccount.php';
$dbhost = $CONF['dbhost'];
$dbuser = $CONF['dbuser'];
$dbpass = $CONF['dbpass'];
$dbname = $CONF['dbname'];
$dbport = $CONF['dbport'];
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbport);
}
示例6: __construct
public function __construct($host = "", $username = "", $passwd = "", $dbname = "")
{
$this->host = $host ? $host : ini_get("mysql.default_host");
$this->username = $username ? $username : ini_get("mysql.default_user");
$this->passwd = $passwd ? $passwd : ini_get("mysql.default_password");
$this->dbname = $dbname ? $dbname : "hb";
parent::__construct($this->host, $this->username, $this->passwd, $this->dbname);
if ($this->connect_errno) {
die('Connect Error (' . $this->connect_errno . ') ' . $this->connect_error);
}
}
示例7: __construct
/**
* Construct from optional connection data
*
* If connection information is not provided, it will be read from the
* corresponding ini options.
*
* @param string $host
* @param string $username
* @param string $passwd
* @param string $dbname
* @param string $port
* @param string $socket
* @return void
*/
public function __construct($host = null, $username = null, $passwd = null, $dbname = null, $port = null, $socket = null)
{
$host = $host ?: ini_get('mysqli.default_host');
$username = $username ?: ini_get('mysqli.default_user');
$passwd = $passwd ?: ini_get('mysqli.default_pw');
$dbname = $dbname ?: '';
$port = $port ?: ini_get('mysqli.default_port');
$socket = $socket ?: ini_get('mysqli.default_socket');
@parent::__construct($host, $username, $passwd, $dbname, $port, $socket);
if ($this->connect_errno) {
throw new \RuntimeException("Could not connect to database: " . $this->connect_error);
}
\mysqli_report(\MYSQLI_REPORT_STRICT);
$this->set_charset("utf8");
}
示例8: __construct
public function __construct($settings = false) {
if(is_array($settings)) {
foreach(array('host', 'username', 'password', 'dbname', 'charset', 'file_log', 'live_log', 'keep_log') as $foo)
if(isset($settings[$foo])) $this->$foo = $settings[$foo];
}
parent::__construct($this->host, $this->username, $this->password, $this->dbname);
if($this->charset) $this->set_charset($this->charset);
if(php_sapi_name() == 'cli') { // running in console
$this->colors = array(
'before_kw' => "\033[1;33m",
'after_kw' => "\033[0m",
'before_qt' => "\033[36m",
'after_qt' => "\033[0m",
'before_bq' => "\033[32m",
'after_bq' => "\033[0m",
'before_info' => "\033[35m",
'after_info' => "\033[0m",
'before_warn' => "\033[32m",
'after_warn' => "\033[0m",
'after_q' => "\n",
);
} else {
$this->colors = array(
'before_kw' => '<span style="color: darkorange">',
'after_kw' => '</span>',
'before_qt' => '<span style="color: blue">',
'after_qt' => '</span>',
'before_bq' => '<span style="color: green">',
'after_bq' => '</span>',
'before_info' => '<span style="color: gray">',
'after_info' => '</span>',
'before_warn' => '<span style="color: red">',
'after_warn' => '</span>',
'after_q' => '<br>',
);
}
}
示例9: __construct
public function __construct($host = null, $user = null, $pass = null, $db = null)
{
if ($host === null) {
ini_get("mysql.default_host");
}
if ($user === null) {
ini_get("mysql.default_user");
}
if ($pass === null) {
ini_get("mysql.default_password");
}
Instrumentation::get_instance()->increment('mysql_connection_count');
Instrumentation::get_instance()->timer();
parent::__construct($host, $user, $pass, $db);
Instrumentation::get_instance()->increment('mysql_connect_time', Instrumentation::get_instance()->timer());
}
示例10: __construct
/**
Class Construct : Connect to MySQL
*/
public function __construct()
{
parent::__construct(BaseConfiguration::$MySQL["host"], BaseConfiguration::$MySQL["user"], BaseConfiguration::$MySQL["pass"], BaseConfiguration::$MySQL["db"]);
}
示例11: __construct
/**
* The constructor will create a new connection with the predefined
* connection details. It's private because of the Singleton pattern.
*/
public function __construct()
{
$aConfiguration = Configuration::getInstance()->get('LVPDatabase');
parent::__construct($aConfiguration['hostname'], $aConfiguration['username'], $aConfiguration['password'], $aConfiguration['database']);
}
示例12: __construct
/**
* Prefents the database class from being instantiated multiple times
*/
private function __construct()
{
$settings = Config::get('database');
return parent::__construct($settings['host'], $settings['user'], $settings['pass'], $settings['name']);
}
示例13: __construct
/**
* Opens connection, sets UTF-8, and autocommit to false
*
*/
public function __construct($host = null, $user = null, $pass = null, $db = null, $port = null, $socket = null)
{
parent::__construct($host, $user, $pass, $db, $port, $socket);
$this->set_charset('utf8');
$this->autocommit(false);
}
示例14: isset
/**
* Skapa en databas-anslutning.
*
* Laddar inställningar från global $repo_root/db_settings/$db_alias.php.
* $host, $user, $passwd och $dbname förväntas vara satta.
*
* @param string $db_alias namnet på anslutningen du vill skapa. (dvs db_settings/$db_alias.php).
*/
function __construct($db_alias, $debug = false)
{
global $repo_root, $notify;
$this->do_debug = $debug;
$settings_basefile = $repo_root . '/db_settings/' . $db_alias;
$settings_file = $settings_basefile . '.php';
$settings_localfile = $settings_basefile . '.local.php';
require $settings_file;
if (file_exists($settings_localfile)) {
require $settings_localfile;
}
$this->db = $dbname;
$this->host = $host;
$this->port = isset($port) ? $port : 3306;
$this->charset = $charset;
$this->start_timer();
parent::__construct($host, $user, $passwd, $dbname, $this->port);
$this->stop_timer();
if (mysqli_connect_errno()) {
if ($this->do_debug) {
$debuginfo = debug_backtrace();
$debuginfo = $debuginfo[0];
print "<p>MySQLi connection problem: " . mysqli_connect_errno() . " (" . mysqli_connect_error() . ").<br />" . "Problem encountered when trying to connect to " . $this->host . ":" . $this->port . ", database " . $this->db . ".<br />" . "The error was encountered in " . $debuginfo['file'] . ":" . $debuginfo['line'] . "<br /></p>";
debug_print_backtrace();
} else {
$notify->admin_alert("Could not connect to SQL database: " . mysqli_connect_errno() . " (" . mysqli_connect_error() . ").", false);
}
die('<p>Kunde inte ansluta till databasen. Var god kontakta oss.</p>');
}
$this->start_timer();
if (!parent::set_charset($charset)) {
if ($this->do_debug) {
$debuginfo = debug_backtrace();
$debuginfo = $debuginfo[0];
print "<p>MySQLi connection problem trying to set charset to \"{$charset}\": " . mysqli_errno() . " (" . mysqli_error() . ").<br />" . "The error was encountered in " . $debuginfo['file'] . ":" . $debuginfo['line'] . "<br /></p>";
debug_print_backtrace();
} else {
$notify->admin_alert("Could not set charset for database connection: " . mysqli_errno() . " (" . mysqli_error() . ").", false);
}
die('<p>Ett problem uppstod med databasanslutningen. Var god kontakta oss.</p>');
}
$this->stop_timer();
unset($user);
unset($host);
unset($passwd);
unset($dbname);
unset($charset);
}
示例15:
function __construct()
{
parent::__construct('*', '*', '*');
parent::select_db('zs1jas_1');
parent::query("SET NAMES utf8");
}