Skip to content

Commit cc88752

Browse files
author
zhouqiang
committed
fix
1 parent 13db8fc commit cc88752

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

Adapter.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* 适配器模式
3+
* 适配器模式, 主要使用适配器来更新接口,而不需要去改动公共接口的标准。
44
* 解决问题:在转换一个对象的接口用于另一个对象时,实现Adapter对象不仅是最佳做法,而且也能减少很多麻烦
55
*/
66
class errorObject
@@ -46,7 +46,7 @@ public function write()
4646
$line = $this->__errorObject->getErrorNumber();
4747
$line .= ",";
4848
$line .= $this->__errorObject->getErrorText();
49-
$Line .= "\n";
49+
$line .= "\n";
5050
file_put_contents(self::CSV_LOCATION, $line, FILE_APPEND);
5151
}
5252
}

Dao.class.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public function __construct()
1414

1515
private function __connectToDB($user, $pass, $host, $database)
1616
{
17-
$this->__connection = mysql_connect($host, $user, $pass);
18-
mysql_select_db($database, $this->__connection);
17+
$this->__connection = mysqli::_connect($host, $user, $pass, $database);
1918
}
2019

2120
public function fetch($value, $key = NULL)
@@ -26,10 +25,10 @@ public function fetch($value, $key = NULL)
2625
}
2726

2827
$sql = "select * from {$this->_tableName} where {$key}='{$value}'";
29-
$results = mysql_query($sql, $this->__connection);
28+
$results = mysqli_query($sql, $this->__connection);
3029

3130
$rows = array();
32-
while ($result = mysql_fetch_array($results))
31+
while ($result = mysqli_fetch_array($results))
3332
{
3433
$rows[] = $result;
3534
}
@@ -45,7 +44,7 @@ public function update($keyedArray)
4544
}
4645
$sql .= implode(",",$updates);
4746
$sql .= "where {$this->_primaryKey}='{$keyedArray[$this->_primaryKey]}'";
48-
mysql_query($sql, $this->__connection);
47+
mysqli:_query($sql, $this->__connection);
4948

5049
}
5150
}

Facade.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
/**
3+
* 这种在laravel框架中门面运用的很多
34
* 外观设计模式的目标是: 控制外部错综复杂的关系, 并且提供简单的接口以利用上述组件的能力。
45
* 为了隐藏复杂的,执行业务进程某个步骤所需的方法和逻辑组,就应当使用基于外观设计模式的类。
56
*

Factory.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
/**
3+
* 抽象工厂模式应该在日常生产过程中运用的很多了
34
* 工厂设计模式: 提供获取某个对象的新实例的一个接口, 同时使调用代码避免确定实际实例化基类的步骤
45
*/
56
//基础标准CD类
@@ -33,6 +34,7 @@ class enhadcedCD extends baseCD{
3334
public $type = 'enhadced';
3435
}
3536

37+
3638
//CD工厂类,实现对以上两个类具体实例化操作
3739
class CDFactory {
3840

Iterator.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ class CDSearchByBandIterator implements Iterator {
2626
private $_valid = FALSE;
2727

2828
public function __construct($bandName) {
29-
$db = mysql_connect("localhost", "root", "root");
30-
mysql_select_db("test");
29+
$db = mysqli_connect("localhost", "root", "root", "test");
30+
mysqli_select_db("test");
3131

3232
$sql = "select CD.id, CD.band, CD.title, tracks.tracknum, tracks.title as tracktitle ";
3333
$sql .= "from CD left join tracks on CD.id = tracks.cid ";
34-
$sql .= "where band = '" . mysql_real_escape_string($bandName) . "' ";
34+
$sql .= "where band = '" . mysqli_real_escape_string($bandName) . "' ";
3535
$sql .= "order by tracks.tracknum";
3636

37-
$results = mysql_query($sql);
37+
$results = mysqli_query($db, $sql);
3838

3939
$cdID = 0;
4040
$cd = NULL;
4141

42-
while ($result = mysql_fetch_array($results)) {
42+
while ($result = mysqli_fetch_array($results)) {
4343
if ($result["id"] !== $cdID) {
4444
if ( ! is_null($cd)) {
4545
$this->_CDs[] = $cd;

Prototype.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class CD {
1010
public $band = "";
1111
public $trackList = array();
1212
public function __construct($id) {
13-
$handle = mysql_connect("localhost", "root", "root");
14-
mysql_select_db("test", $handle);
13+
$handle = mysqli_connect("localhost", "root", "root");
14+
mysqli_select_db("test", $handle);
1515

1616
$query = "select * from cd where id = {$id}";
17-
$results= mysql_query($query, $handle);
17+
$results= mysqli_query($query, $handle);
1818

19-
if ($row = mysql_fetch_assoc($results)) {
19+
if ($row = mysqli_fetch_assoc($results)) {
2020
$this->band = $row["band"];
2121
$this->title = $row["title"];
2222
}

Proxy.class.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ public function buy() {
2020
$this->_connect();
2121

2222
$query = "update cd set bought = 1 where band = '";
23-
$query .= mysql_real_escape_string($this->_band, $this->_handle);
23+
$query .= mysqli_real_escape_string($this->_band, $this->_handle);
2424
$query .= " ' and title = '";
25-
$query .= mysql_real_escape_string($this->_title, $this->_handle);
25+
$query .= mysqli_real_escape_string($this->_title, $this->_handle);
2626
$query .= "'";
2727

28-
mysql_query($query, $this->_handle);
28+
mysqli_query($query, $this->_handle);
2929

3030
//var_dump("success");
3131
}
3232

3333
protected function _connect() {
34-
$this->_handle = mysql_connect("localhost", "root", "root");
35-
mysql_select_db("test", $this->_handle);
34+
$this->_handle = mysqli_connect("localhost", "root", "root");
35+
mysqli_select_db("test", $this->_handle);
3636
}
3737
}
3838

@@ -42,8 +42,8 @@ protected function _connect() {
4242
//代理类
4343
class DallasNoCCDProxy extends CD {
4444
protected function _connect() {
45-
$this->_handle = mysql_connect("dallas", "user", "pass");
46-
mysql_select_db("test", $this->_handle);
45+
$this->_handle = mysqli_connect("dallas", "user", "pass");
46+
mysqli_select_db("test", $this->_handle);
4747
}
4848
}
4949

0 commit comments

Comments
 (0)