mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Replaced deprecated mysql_* functions
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@332224 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
b18ed2abf4
commit
45497f188a
1 changed files with 7 additions and 9 deletions
|
@ -87,37 +87,35 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
<?php
|
||||
class Connection
|
||||
{
|
||||
protected $link;
|
||||
private $server, $username, $password, $db;
|
||||
private $dsn, $username, $password;
|
||||
|
||||
public function __construct($server, $username, $password, $db)
|
||||
public function __construct($dsn, $username, $password)
|
||||
{
|
||||
$this->server = $server;
|
||||
$this->dsn = $dsn;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->db = $db;
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
private function connect()
|
||||
{
|
||||
$this->link = mysql_connect($this->server, $this->username, $this->password);
|
||||
mysql_select_db($this->db, $this->link);
|
||||
$this->link = new PDO($this->dsn, $this->username, $this->password);
|
||||
}
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return array('server', 'username', 'password', 'db');
|
||||
return array('dsn', 'username', 'password');
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->connect();
|
||||
}
|
||||
}
|
||||
?>
|
||||
}?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue