-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.php
More file actions
74 lines (69 loc) · 2.05 KB
/
test.php
File metadata and controls
74 lines (69 loc) · 2.05 KB
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
<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
require 'MySQLColumn.php';
require 'MySQLTable.php';
require 'MySQLQuery.php';
require 'MySQLLink.php';
use phMysql\MySQLColumn;
use phMysql\MySQLLink;
use phMysql\MySQLQuery;
use phMysql\Table;
class Q extends MySQLQuery {
/**
*
* @var Table
*/
private $table;
public function __construct() {
parent::__construct();
$this->table = new Table('test_table');
$this->table->addColumn('col-1', new MySQLColumn('x_col', 'varchar', 25));
$this->table->addColumn('col-2', new MySQLColumn('yc_col', 'varchar', 225));
$this->table->addColumn('col-3', new MySQLColumn('x_ncol', 'int', 3));
}
public function getStructure() {
return $this->table;
}
}
$link = new MySQLLink('localhost', 'root', 'xxxx');
if ($link->isConnected()) {
print_message('Connected.');
$result = $link->setDB('x_db');
if ($result === true) {
print_message('Database Selected.');
$q = new Q();
$q->select();
print_message($q->getQuery());
$result = $link->executeQuery($q);
if ($result === true) {
print_message('Query was executed.');
var_dump($link->getColumn('col-3'));
fetchRows($link);
} else {
print_message('Query not executed.');
print_message('Error Number: '.$link->getErrorCode());
print_message('Details: '.$link->getErrorMessage());
}
} else {
print_message('Unable to select database.');
print_message('Error Number: '.$link->getErrorCode());
print_message('Details: '.$link->getErrorMessage());
}
} else {
print_message('Error Number: '.$link->getErrorCode());
print_message('Details: '.$link->getErrorMessage());
}
function print_message($message) {
echo '<pre>'.$message.'</pre>';
}
/**
*
* @param DatabaseLink $link
*/
function fetchRows($link) {
while ($row = $link->getRow()) {
?><pre><?php print_r($row)?></pre><?php
}
}