Maison php教程 php手册 ecshop适应PHP7的修改 - 龙翔天下

ecshop适应PHP7的修改 - 龙翔天下

May 20, 2016 am 10:14 AM

说实话,ecshop这个系统,到目前也没见怎么推出新版本,如果是新项目,不太建议使用它。不过,因为我一直以来都在使用中,所以不得不更改让其适应PHP新版本。现在PHP 7已经出发行版了,所以更改来继续使用吧。具体的更改有以下方面:

(1)将mysql扩展的使用替换掉,改为使用mysqli或pdo:

从php5.5开始,mysql扩展将废弃了。

具体更改的文件在于includes/cls_mysql.php。这是个不小的工程,文件代码太长……

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

<span style="color: #0000ff;">if</span> (!<span style="color: #008080;">defined</span>('DITAN_ECS'<span style="color: #000000;">))

{

    </span><span style="color: #0000ff;">die</span>('Hacking attempt'<span style="color: #000000;">);

}

 

</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> cls_mysql

{

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$link_id</span>    = <span style="color: #0000ff;">NULL</span><span style="color: #000000;">;

 

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$settings</span>   = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

 

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$queryCount</span> = 0<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$queryTime</span>  = ''<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$queryLog</span>   = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

 

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$max_cache_time</span> = 300; <span style="color: #008000;">//</span><span style="color: #008000;"> 最大的缓存时间,以秒为单位</span>

 

    <span style="color: #0000ff;">var</span> <span style="color: #800080;">$cache_data_dir</span> = 'temp/query_caches/'<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$root_path</span>      = ''<span style="color: #000000;">;

 

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$error_message</span>  = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$platform</span>       = ''<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$version</span>        = ''<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$dbhash</span>         = ''<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$starttime</span>      = 0<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$timeline</span>       = 0<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$timezone</span>       = 0<span style="color: #000000;">;

    </span><span style="color: #008000;">//</span><span style="color: #008000;"> 事务指令数</span>

    <span style="color: #0000ff;">protected</span> <span style="color: #800080;">$transTimes</span> = 0<span style="color: #000000;">;

 

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$mysql_config_cache_file_time</span> = 0<span style="color: #000000;">;

 

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$mysql_disable_cache_tables</span> = <span style="color: #0000ff;">array</span>(); <span style="color: #008000;">//</span><span style="color: #008000;"> 不允许被缓存的表,遇到将不会进行缓存</span>

 

    <span style="color: #0000ff;">function</span> __construct(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span> = '', <span style="color: #800080;">$charset</span> = 'gbk', <span style="color: #800080;">$pconnect</span> = 0, <span style="color: #800080;">$quiet</span> = 0<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$this</span>->cls_mysql(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span>, <span style="color: #800080;">$charset</span>, <span style="color: #800080;">$pconnect</span>, <span style="color: #800080;">$quiet</span><span style="color: #000000;">);

    }

 

    </span><span style="color: #0000ff;">function</span> cls_mysql(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span> = '', <span style="color: #800080;">$charset</span> = 'gbk', <span style="color: #800080;">$pconnect</span> = 0, <span style="color: #800080;">$quiet</span> = 0<span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">defined</span>('EC_CHARSET'<span style="color: #000000;">))

        {

            </span><span style="color: #800080;">$charset</span> = <span style="color: #008080;">strtolower</span>(<span style="color: #008080;">str_replace</span>('-', '',<span style="color: #000000;"> EC_CHARSET));

        }

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">defined</span>('ROOT_PATH') && !<span style="color: #800080;">$this</span>-><span style="color: #000000;">root_path)

        {

            </span><span style="color: #800080;">$this</span>->root_path =<span style="color: #000000;"> ROOT_PATH;

        }

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$quiet</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->connect(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span>, <span style="color: #800080;">$charset</span>, <span style="color: #800080;">$pconnect</span>, <span style="color: #800080;">$quiet</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$this</span>->settings = <span style="color: #0000ff;">array</span><span style="color: #000000;">(

                                    </span>'dbhost'   => <span style="color: #800080;">$dbhost</span>,

                                    'dbuser'   => <span style="color: #800080;">$dbuser</span>,

                                    'dbpw'     => <span style="color: #800080;">$dbpw</span>,

                                    'dbname'   => <span style="color: #800080;">$dbname</span>,

                                    'charset'  => <span style="color: #800080;">$charset</span>,

                                    'pconnect' => <span style="color: #800080;">$pconnect</span><span style="color: #000000;">

                                    );

        }

    }

 

    </span><span style="color: #0000ff;">function</span> connect(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span> = '', <span style="color: #800080;">$charset</span> = 'utf8', <span style="color: #800080;">$pconnect</span> = 0, <span style="color: #800080;">$quiet</span> = 0<span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$pconnect</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->link_id = <span style="color: #0000ff;">new</span> mysqli('p:'.<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span><span style="color: #000000;">);

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">connect_error)

            {

                </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$quiet</span><span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$this</span>->ErrorMsg("Can't pConnect MySQL Server(<span style="color: #800080;">$dbhost</span>)!"<span style="color: #000000;">);

                }

 

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

            }

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$this</span>->link_id = <span style="color: #0000ff;">new</span> mysqli(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span><span style="color: #000000;">);

 

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">connect_error)

            {

                </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$quiet</span><span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$this</span>->ErrorMsg("Can't Connect MySQL Server(<span style="color: #800080;">$dbhost</span>)!"<span style="color: #000000;">);

                }

 

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

            }

        }

 

        </span><span style="color: #800080;">$this</span>->dbhash  = <span style="color: #008080;">md5</span>(<span style="color: #800080;">$this</span>->root_path . <span style="color: #800080;">$dbhost</span> . <span style="color: #800080;">$dbuser</span> . <span style="color: #800080;">$dbpw</span> . <span style="color: #800080;">$dbname</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$this</span>->version = <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">server_version;

 

        </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 对字符集进行初始化 </span><span style="color: #008000;">*/</span>

        <span style="color: #800080;">$this</span>->link_id->set_charset(<span style="color: #800080;">$charset</span><span style="color: #000000;">);

         

        </span><span style="color: #800080;">$this</span>->link_id->query("SET sql_mode=''"<span style="color: #000000;">);

        </span><span style="color: #800080;">$sqlcache_config_file</span> = <span style="color: #800080;">$this</span>->root_path . <span style="color: #800080;">$this</span>->cache_data_dir . 'sqlcache_config_file_' . <span style="color: #800080;">$this</span>->dbhash . '.php'<span style="color: #000000;">;

 

        @</span><span style="color: #0000ff;">include</span>(<span style="color: #800080;">$sqlcache_config_file</span><span style="color: #000000;">);

 

        </span><span style="color: #800080;">$this</span>->starttime = <span style="color: #008080;">time</span><span style="color: #000000;">();

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->max_cache_time && <span style="color: #800080;">$this</span>->starttime > <span style="color: #800080;">$this</span>->mysql_config_cache_file_time + <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time)

        {

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$dbhost</span> != '.'<span style="color: #000000;">)

            {

                </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->link_id->query("SHOW VARIABLES LIKE 'basedir'"<span style="color: #000000;">);

                </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$result</span>-><span style="color: #000000;">fetch_array(MYSQLI_ASSOC);

                </span><span style="color: #800080;">$result</span>-><span style="color: #000000;">free();

                </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$row</span>['Value']{1}) && <span style="color: #800080;">$row</span>['Value']{1} == ':' && !<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$row</span>['Value']{2}) && <span style="color: #800080;">$row</span>['Value']{2} == "/"<span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$this</span>->platform = 'WINDOWS'<span style="color: #000000;">;

                }

                </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

                {

                    </span><span style="color: #800080;">$this</span>->platform = 'OTHER'<span style="color: #000000;">;

                }

            }

            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

            {

                </span><span style="color: #800080;">$this</span>->platform = 'WINDOWS'<span style="color: #000000;">;

            }

 

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->platform == 'OTHER' &&<span style="color: #000000;">

                (</span><span style="color: #800080;">$dbhost</span> != '.' && <span style="color: #008080;">strtolower</span>(<span style="color: #800080;">$dbhost</span>) != 'localhost:3306' && <span style="color: #800080;">$dbhost</span> != '127.0.0.1:3306') ||<span style="color: #000000;">

                date_default_timezone_get() </span>== 'UTC'<span style="color: #000000;">)

            {

                </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->link_id->query("SELECT UNIX_TIMESTAMP() AS timeline, UNIX_TIMESTAMP('" . <span style="color: #008080;">date</span>('Y-m-d H:i:s', <span style="color: #800080;">$this</span>->starttime) . "') AS timezone"<span style="color: #000000;">);

                </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$result</span>-><span style="color: #000000;">fetch_array(MYSQLI_ASSOC);

                </span><span style="color: #800080;">$result</span>-><span style="color: #000000;">free();

                </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$dbhost</span> != '.' && <span style="color: #008080;">strtolower</span>(<span style="color: #800080;">$dbhost</span>) != 'localhost:3306' && <span style="color: #800080;">$dbhost</span> != '127.0.0.1:3306'<span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$this</span>->timeline = <span style="color: #800080;">$this</span>->starttime - <span style="color: #800080;">$row</span>['timeline'<span style="color: #000000;">];

                }

                </span><span style="color: #0000ff;">if</span> (date_default_timezone_get() == 'UTC'<span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$this</span>->timezone = <span style="color: #800080;">$this</span>->starttime - <span style="color: #800080;">$row</span>['timezone'<span style="color: #000000;">];

                }

            }

 

            </span><span style="color: #800080;">$content</span> = 'mysql_config_cache_file_time = ' . <span style="color: #800080;">$this</span>->starttime . ";\r\n" .

                       '$this->timeline = ' . <span style="color: #800080;">$this</span>->timeline . ";\r\n" .

                       '$this->timezone = ' . <span style="color: #800080;">$this</span>->timezone . ";\r\n" .

                       '$this->platform = ' . "'" . <span style="color: #800080;">$this</span>->platform . "';\r\n?" . '>'<span style="color: #000000;">;

 

            @</span><span style="color: #008080;">file_put_contents</span>(<span style="color: #800080;">$sqlcache_config_file</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">);

        }

 

        </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 选择数据库 </span><span style="color: #008000;">*/</span>

        <span style="color: #0000ff;">if</span> (<span style="color: #800080;">$dbname</span><span style="color: #000000;">)

        {

             

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id->select_db(<span style="color: #800080;">$dbname</span>) === <span style="color: #0000ff;">false</span><span style="color: #000000;"> )

            {

                </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$quiet</span><span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$this</span>->ErrorMsg("Can't select MySQL database(<span style="color: #800080;">$dbname</span>)!"<span style="color: #000000;">);

                }

 

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

            }

            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

            {

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;

            }

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;

        }

    }

 

    </span><span style="color: #0000ff;">function</span> select_database(<span style="color: #800080;">$dbname</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id->select_db(<span style="color: #800080;">$dbname</span><span style="color: #000000;">);

    }

 

    </span><span style="color: #0000ff;">function</span> set_mysql_charset(<span style="color: #800080;">$charset</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">in_array</span>(<span style="color: #008080;">strtolower</span>(<span style="color: #800080;">$charset</span>), <span style="color: #0000ff;">array</span>('gbk', 'big5', 'utf-8', 'utf8'<span style="color: #000000;">)))

        {

            </span><span style="color: #800080;">$charset</span> = <span style="color: #008080;">str_replace</span>('-', '', <span style="color: #800080;">$charset</span><span style="color: #000000;">);

        }

        </span><span style="color: #800080;">$this</span>->link_id->set_charset(<span style="color: #800080;">$charset</span><span style="color: #000000;">);

    }

 

    </span><span style="color: #0000ff;">function</span> fetch_array(<span style="color: #800080;">$query</span>, <span style="color: #800080;">$result_type</span> =<span style="color: #000000;"> MYSQLI_ASSOC)

    {

        </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$query</span>->fetch_array(<span style="color: #800080;">$result_type</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$query</span>-><span style="color: #000000;">free();

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$row</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span> query(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$type</span> = ''<span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id === <span style="color: #0000ff;">NULL</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->connect(<span style="color: #800080;">$this</span>->settings['dbhost'], <span style="color: #800080;">$this</span>->settings['dbuser'], <span style="color: #800080;">$this</span>->settings['dbpw'], <span style="color: #800080;">$this</span>->settings['dbname'], <span style="color: #800080;">$this</span>->settings['charset'], <span style="color: #800080;">$this</span>->settings['pconnect'<span style="color: #000000;">]);

            </span><span style="color: #800080;">$this</span>->settings = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

        }

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->queryCount++ )

        {

            <span style="color: #800080;">$this</span>->queryLog[] = <span style="color: #800080;">$sql</span><span style="color: #000000;">;

        }

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->queryTime == ''<span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">if</span> (<span style="color: #ff00ff;">PHP_VERSION</span> >= '5.0.0'<span style="color: #000000;">)

            {

                </span><span style="color: #800080;">$this</span>->queryTime = <span style="color: #008080;">microtime</span>(<span style="color: #0000ff;">true</span><span style="color: #000000;">);

            }

            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

            {

                </span><span style="color: #800080;">$this</span>->queryTime = <span style="color: #008080;">microtime</span><span style="color: #000000;">();

            }

        }

 

        </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 当当前的时间大于类初始化时间的时候,自动执行 ping 这个自动重新连接操作 </span><span style="color: #008000;">*/</span>

        <span style="color: #0000ff;">if</span> (<span style="color: #008080;">time</span>() > <span style="color: #800080;">$this</span>->starttime + 1<span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">ping();

        }

 

        </span><span style="color: #0000ff;">if</span> (!(<span style="color: #800080;">$query</span> = <span style="color: #800080;">$this</span>->link_id->query(<span style="color: #800080;">$sql</span>)) && <span style="color: #800080;">$type</span> != 'SILENT'<span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->error_message[]['message'] = 'MySQL Query Error'<span style="color: #000000;">;

            </span><span style="color: #800080;">$this</span>->error_message[]['sql'] = <span style="color: #800080;">$sql</span><span style="color: #000000;">;

            </span><span style="color: #800080;">$this</span>->error_message[]['error'] = <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">error;

            </span><span style="color: #800080;">$this</span>->error_message[]['errno'] = <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">errno;

 

            </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">ErrorMsg();

 

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

        }

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">defined</span>('DEBUG_MODE') && (DEBUG_MODE & 8) == 8<span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$logfilename</span> = <span style="color: #800080;">$this</span>->root_path . DATA_DIR . '/mysql_query_' . <span style="color: #800080;">$this</span>->dbhash . '_' . <span style="color: #008080;">date</span>('Y_m_d') . '.log'<span style="color: #000000;">;

            </span><span style="color: #800080;">$str</span> = <span style="color: #800080;">$sql</span> . "\n\n"<span style="color: #000000;">;

 

            </span><span style="color: #0000ff;">if</span> (<span style="color: #ff00ff;">PHP_VERSION</span> >= '5.0'<span style="color: #000000;">)

            {

                </span><span style="color: #008080;">file_put_contents</span>(<span style="color: #800080;">$logfilename</span>, <span style="color: #800080;">$str</span>,<span style="color: #000000;"> FILE_APPEND);

            }

            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

            {

                </span><span style="color: #800080;">$fp</span> = @<span style="color: #008080;">fopen</span>(<span style="color: #800080;">$logfilename</span>, 'ab+'<span style="color: #000000;">);

                </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$fp</span><span style="color: #000000;">)

                {

                    </span><span style="color: #008080;">fwrite</span>(<span style="color: #800080;">$fp</span>, <span style="color: #800080;">$str</span><span style="color: #000000;">);

                    </span><span style="color: #008080;">fclose</span>(<span style="color: #800080;">$fp</span><span style="color: #000000;">);

                }

            }

        }

 

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> affected_rows()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">affected_rows;

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> error()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">error;

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> errno()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">errno;

    }

 

    </span><span style="color: #0000ff;">function</span> result(<span style="color: #800080;">$query</span>, <span style="color: #800080;">$row</span><span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$query</span>->data_seek(<span style="color: #800080;">$row</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$query</span>-><span style="color: #000000;">fetch_row();

        </span><span style="color: #800080;">$query</span>-><span style="color: #000000;">free();

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span> num_rows(<span style="color: #800080;">$query</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">num_rows;

    }

 

    </span><span style="color: #0000ff;">function</span> num_fields(<span style="color: #800080;">$query</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">field_count;

    }

 

    </span><span style="color: #0000ff;">function</span> free_result(<span style="color: #800080;">$query</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">free();

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> insert_id()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">insert_id;

    }

 

    </span><span style="color: #0000ff;">function</span> fetchRow(<span style="color: #800080;">$query</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">fetch_assoc();

    }

 

    </span><span style="color: #0000ff;">function</span> fetch_fields(<span style="color: #800080;">$query</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">fetch_field();

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> version()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">version;

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> ping()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">ping();

    }

 

    </span><span style="color: #0000ff;">function</span> escape_string(<span style="color: #800080;">$unescaped_string</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id->real_escape_string(<span style="color: #800080;">$unescaped_string</span><span style="color: #000000;">);

    }

 

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> close()

    {

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">close();

    }

 

    </span><span style="color: #0000ff;">function</span> ErrorMsg(<span style="color: #800080;">$message</span> = '', <span style="color: #800080;">$sql</span> = ''<span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$message</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">echo</span> "<b>DTXB info</b>: <span style="color: #800080;">$message</span>\n\n<br><br>"<span style="color: #000000;">;

            </span><span style="color: #008000;">//</span><span style="color: #008000;">print('<a href="http://faq.comsenz.com/?type=mysql&dberrno=2003&dberror=Can%27t%20connect%20to%20MySQL%20server%20on" target="_blank">http://faq.comsenz.com/</a>');</span>

<span style="color: #000000;">        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">echo</span> "<b>MySQL server error report:"<span style="color: #000000;">;

            </span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">error_message);

            </span><span style="color: #008000;">//</span><span style="color: #008000;">echo "<br><br><a href="http://faq.comsenz.com/?type=mysql&dberrno=%22%20.%20%24this->error_message%5B3%5D%5B" errno . urlencode>error_message[2]['error']) . "' target='_blank'>http://faq.comsenz.com/</a>";</span>

<span style="color: #000000;">        }

 

        </span><span style="color: #0000ff;">exit</span><span style="color: #000000;">;

    }

 

</span><span style="color: #008000;">/*</span><span style="color: #008000;"> 仿真 Adodb 函数 </span><span style="color: #008000;">*/</span>

    <span style="color: #0000ff;">function</span> selectLimit(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$num</span>, <span style="color: #800080;">$start</span> = 0<span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$start</span> == 0<span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$sql</span> .= ' LIMIT ' . <span style="color: #800080;">$num</span><span style="color: #000000;">;

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$sql</span> .= ' LIMIT ' . <span style="color: #800080;">$start</span> . ', ' . <span style="color: #800080;">$num</span><span style="color: #000000;">;

        }

 

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

    }

 

    </span><span style="color: #0000ff;">function</span> getOne(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$limited</span> = <span style="color: #0000ff;">false</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$limited</span> == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$sql</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$sql</span> . ' LIMIT 1'<span style="color: #000000;">);

        }

 

        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_row();

            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$row</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$row</span>[0<span style="color: #000000;">];

            }

            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

            {

                </span><span style="color: #0000ff;">return</span> ''<span style="color: #000000;">;

            }

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

        }

    }

 

    </span><span style="color: #0000ff;">function</span> getOneCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$sql</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$sql</span> . ' LIMIT 1'<span style="color: #000000;">);

 

        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;

        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getOne(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);

            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];

            }

        }

 

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getOne(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);

        }

 

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span> getAll(<span style="color: #800080;">$sql</span><span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_all(MYSQLI_ASSOC);

            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();

             </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

        }

    }

 

    </span><span style="color: #0000ff;">function</span> getAllCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;

        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getAll(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);

            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];

            }

        }

 

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getAll(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);

        }

 

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span> getRow(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$limited</span> = <span style="color: #0000ff;">false</span><span style="color: #000000;">)

    {

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$limited</span> == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$sql</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$sql</span> . ' LIMIT 1'<span style="color: #000000;">);

        }

 

        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_assoc();

            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

        }

    }

 

    </span><span style="color: #0000ff;">function</span> getRowCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;

        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getRow(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);

            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];

            }

        }

 

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getRow(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);

        }

 

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span> getCol(<span style="color: #800080;">$sql</span><span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$arr</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

            </span><span style="color: #0000ff;">while</span> (<span style="color: #800080;">$row</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_row())

            {

                </span><span style="color: #800080;">$arr</span>[] = <span style="color: #800080;">$row</span>[0<span style="color: #000000;">];

            }

            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

        }

    }

 

    </span><span style="color: #0000ff;">function</span> getColCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;

        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getCol(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);

            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];

            }

        }

 

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getCol(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);

        }

 

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;

    }

 

    </span><span style="color: #0000ff;">function</span> autoExecute(<span style="color: #800080;">$table</span>, <span style="color: #800080;">$field_values</span>, <span style="color: #800080;">$mode</span> = 'INSERT', <span style="color: #800080;">$where</span> = '', <span style="color: #800080;">$querymode</span> = ''<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$field_names</span> = <span style="color: #800080;">$this</span>->getCol('DESC ' . <span style="color: #800080;">$table</span><span style="color: #000000;">);

 

        </span><span style="color: #800080;">$sql</span> = ''<span style="color: #000000;">;

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$mode</span> == 'INSERT'<span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$fields</span> = <span style="color: #800080;">$values</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

            </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_names</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$value</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$fields</span>[] = <span style="color: #800080;">$value</span><span style="color: #000000;">;

                    </span><span style="color: #800080;">$values</span>[] = "'" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;

                }

            }

 

            </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">))

            {

                </span><span style="color: #800080;">$sql</span> = 'INSERT INTO ' . <span style="color: #800080;">$table</span> . ' (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$fields</span>) . ') VALUES (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$values</span>) . ')'<span style="color: #000000;">;

            }

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #800080;">$sets</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

            </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_names</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$value</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

                {

                    </span><span style="color: #800080;">$sets</span>[] = <span style="color: #800080;">$value</span> . " = '" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;

                }

            }

 

            </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$sets</span><span style="color: #000000;">))

            {

                </span><span style="color: #800080;">$sql</span> = 'UPDATE ' . <span style="color: #800080;">$table</span> . ' SET ' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$sets</span>) . ' WHERE ' . <span style="color: #800080;">$where</span><span style="color: #000000;">;

            }

        }

 

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$sql</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$querymode</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;

        }

    }

 

    </span><span style="color: #0000ff;">function</span> autoReplace(<span style="color: #800080;">$table</span>, <span style="color: #800080;">$field_values</span>, <span style="color: #800080;">$update_values</span>, <span style="color: #800080;">$where</span> = '', <span style="color: #800080;">$querymode</span> = ''<span style="color: #000000;">)

    {

        </span><span style="color: #800080;">$field_descs</span> = <span style="color: #800080;">$this</span>->getAll('DESC ' . <span style="color: #800080;">$table</span><span style="color: #000000;">);

 

        </span><span style="color: #800080;">$primary_keys</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_descs</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)

        {

            </span><span style="color: #800080;">$field_names</span>[] = <span style="color: #800080;">$value</span>['Field'<span style="color: #000000;">];

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$value</span>['Key'] == 'PRI'<span style="color: #000000;">)

            {

                </span><span style="color: #800080;">$primary_keys</span>[] = <span style="color: #800080;">$value</span>['Field'<span style="color: #000000;">];

            }

        }

 

        </span><span style="color: #800080;">$fields</span> = <span style="color: #800080;">$values</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_names</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$value</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

            {

                </span><span style="color: #800080;">$fields</span>[] = <span style="color: #800080;">$value</span><span style="color: #000000;">;

                </span><span style="color: #800080;">$values</span>[] = "'" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;

            }

        }

 

        </span><span style="color: #800080;">$sets</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$update_values</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">)

        {

            </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$key</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_int</span>(<span style="color: #800080;">$value</span>) || <span style="color: #008080;">is_float</span>(<span style="color: #800080;">$value</span><span style="color: #000000;">))

                {

                    </span><span style="color: #800080;">$sets</span>[] = <span style="color: #800080;">$key</span> . ' = ' . <span style="color: #800080;">$key</span> . ' + ' . <span style="color: #800080;">$value</span><span style="color: #000000;">;

                }

                </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

                {

                    </span><span style="color: #800080;">$sets</span>[] = <span style="color: #800080;">$key</span> . " = '" . <span style="color: #800080;">$value</span> . "'"<span style="color: #000000;">;

                }

            }

        }

 

        </span><span style="color: #800080;">$sql</span> = ''<span style="color: #000000;">;

        </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$primary_keys</span><span style="color: #000000;">))

        {

            </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">))

            {

                </span><span style="color: #800080;">$sql</span> = 'INSERT INTO ' . <span style="color: #800080;">$table</span> . ' (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$fields</span>) . ') VALUES (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$values</span>) . ')'<span style="color: #000000;">;

            }

        }

        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

        {

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->version() >= '4.1'<span style="color: #000000;">)

            {

                </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">))

                {

                    </span><span style="color: #800080;">$sql</span> = 'INSERT INTO ' . <span style="color: #800080;">$table</span> . ' (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$fields</span>) . ') VALUES (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$values</span>) . ')'<span style="color: #000000;">;

                    </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$sets</span><span style="color: #000000;">))

                    {

                        </span><span style="color: #800080;">$sql</span> .=  'ON DUPLICATE KEY UPDATE ' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$sets</span><span style="color: #000000;">);

                    }

                }

            }

            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

            {

                </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$where</span><span style="color: #000000;">))

                {

                    </span><span style="color: #800080;">$where</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

                    </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$primary_keys</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)

                    {

                        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_numeric</span>(<span style="color: #800080;">$value</span><span style="color: #000000;">))

                        {

                            </span><span style="color: #800080;">$where</span>[] = <span style="color: #800080;">$value</span> . ' = ' . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span><span style="color: #000000;">];

                        }

                        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">

                        {

                            </span><span style="color: #800080;">$where</span>[] = <span style="color: #800080;">$value</span> . " = '" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;

                        }

                    }

                    </span><span style="color: #800080;">$where</span> = <span style="color: #008080;">implode</span>(' AND ', <span style="color: #800080;">$where</span><span style="color: #000000;">);

                }

 

                </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$where</span> && (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$sets</span>) || !<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">)))

                {

                    </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">intval</span>(<span style="color: #800080;">$this</span>->getOne("SELECT COUNT(*) FROM <span style="color: #800080;">$table</span> WHERE <span style="color: #800080;">$where</span>")) > 0<span style="color: #000000;">)

                    {

                        </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #8"></span></b>

Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
2 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
1 Il y a quelques mois By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
4 Il y a quelques semaines By DDD
Musée à deux points: toutes les expositions et où les trouver
1 Il y a quelques mois By 尊渡假赌尊渡假赌尊渡假赌

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)