Skip to content

Commit b7d3bd6

Browse files
committed
sqlite.class.php
0 parents  commit b7d3bd6

File tree

3 files changed

+359
-0
lines changed

3 files changed

+359
-0
lines changed

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.gitignore

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
[Dd]ebug/
46+
[Rr]elease/
47+
*_i.c
48+
*_p.c
49+
*.ilk
50+
*.meta
51+
*.obj
52+
*.pch
53+
*.pdb
54+
*.pgc
55+
*.pgd
56+
*.rsp
57+
*.sbr
58+
*.tlb
59+
*.tli
60+
*.tlh
61+
*.tmp
62+
*.vspscc
63+
.builds
64+
*.dotCover
65+
66+
## TODO: If you have NuGet Package Restore enabled, uncomment this
67+
#packages/
68+
69+
# Visual C++ cache files
70+
ipch/
71+
*.aps
72+
*.ncb
73+
*.opensdf
74+
*.sdf
75+
76+
# Visual Studio profiler
77+
*.psess
78+
*.vsp
79+
80+
# ReSharper is a .NET coding add-in
81+
_ReSharper*
82+
83+
# Installshield output folder
84+
[Ee]xpress
85+
86+
# DocProject is a documentation generator add-in
87+
DocProject/buildhelp/
88+
DocProject/Help/*.HxT
89+
DocProject/Help/*.HxC
90+
DocProject/Help/*.hhc
91+
DocProject/Help/*.hhk
92+
DocProject/Help/*.hhp
93+
DocProject/Help/Html2
94+
DocProject/Help/html
95+
96+
# Click-Once directory
97+
publish
98+
99+
# Others
100+
[Bb]in
101+
[Oo]bj
102+
sql
103+
TestResults
104+
*.Cache
105+
ClientBin
106+
stylecop.*
107+
~$*
108+
*.dbmdl
109+
Generated_Code #added for RIA/Silverlight projects
110+
111+
# Backup & report files from converting an old project file to a newer
112+
# Visual Studio version. Backup files are not needed, because we have git ;-)
113+
_UpgradeReport_Files/
114+
Backup*/
115+
UpgradeLog*.XML
116+
117+
118+
119+
############
120+
## Windows
121+
############
122+
123+
# Windows image file caches
124+
Thumbs.db
125+
126+
# Folder config file
127+
Desktop.ini
128+
129+
130+
#############
131+
## Python
132+
#############
133+
134+
*.py[co]
135+
136+
# Packages
137+
*.egg
138+
*.egg-info
139+
dist
140+
build
141+
eggs
142+
parts
143+
bin
144+
var
145+
sdist
146+
develop-eggs
147+
.installed.cfg
148+
149+
# Installer logs
150+
pip-log.txt
151+
152+
# Unit test / coverage reports
153+
.coverage
154+
.tox
155+
156+
#Translations
157+
*.mo
158+
159+
#Mr Developer
160+
.mr.developer.cfg
161+
162+
# Mac crap
163+
.DS_Store

sqlite.class.php

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
/*
3+
http://lampacore.ru/2012/06/10/sqliteclass/
4+
*/
5+
class SQLite {
6+
public $file;
7+
public $db;
8+
public $query;
9+
public $prepare;
10+
//
11+
const IS_INT = 1;
12+
const IS_STR = 2;
13+
const ASSOC = 1;
14+
const NUM = 2;
15+
const BOTH = 3;
16+
17+
function __construct($base, $mode = 0666, $auto = true) {
18+
$this->db_file = $base;
19+
//
20+
return $auto?$this->open($mode):true;
21+
}
22+
23+
function open($mode) {
24+
if($this->db) return $this->db;
25+
//
26+
if(!$this->db_file) return FALSE;
27+
//
28+
if(!is_file($this->db_file)) return FALSE;
29+
//
30+
if($this->db = sqlite_open ($this->db_file, $mode, $error)) {
31+
//
32+
return $this->db;
33+
}
34+
else{
35+
$this->error($error);
36+
return FALSE;
37+
}
38+
}
39+
40+
function close() {
41+
$this->error = '';
42+
sqlite_close($this->db);
43+
return true;
44+
}
45+
46+
function query($query) {
47+
$query = preg_replace("/escape_string\((.*?)\)/", $this->escape_string("$1"), $query);
48+
$this->query = sqlite_query($this->db, $query);
49+
return $this;
50+
}
51+
52+
function fetch($type=SQLITE_BOTH) {
53+
if($type == 1) {
54+
$type = SQLITE_ASSOC;
55+
}
56+
elseif($type == 2) {
57+
$type = SQLITE_NUM;
58+
}
59+
elseif($type == 3 || $type != SQLITE_BOTH) {
60+
$type = SQLITE_BOTH;
61+
}
62+
//
63+
return sqlite_fetch_array($this->query, $type);
64+
}
65+
66+
function fetchAll($type=SQLITE_BOTH) {
67+
if($type == 1) {
68+
$type = SQLITE_ASSOC;
69+
}
70+
elseif($type == 2) {
71+
$type = SQLITE_NUM;
72+
}
73+
elseif($type == 3 || $type != SQLITE_BOTH) {
74+
$type = SQLITE_BOTH;
75+
}
76+
//
77+
return sqlite_fetch_all($this->query, $type);
78+
}
79+
80+
81+
function prepare($query) {
82+
$this->prepare = $query;
83+
return $this;
84+
}
85+
86+
function bindParam($bind, $value, $types = '') {
87+
//
88+
if($types == 1) {
89+
if(preg_match("/^\d+$/", $value)) $to_prepare = $value;
90+
}
91+
elseif($types == 2) {
92+
if(is_string($value)) $to_prepare = '"'.$this->escape_string($value).'"';
93+
}
94+
elseif(!empty($types)) {
95+
if(preg_match($types, $value)) '"'.$this->escape_string($value).'"';
96+
}
97+
//
98+
if(empty($to_prepare)) $to_prepare = '""';
99+
100+
//
101+
$this->prepare = str_replace($bind, $to_prepare, $this->prepare);
102+
//
103+
return $this;
104+
}
105+
106+
function execute() {
107+
//
108+
$this->query = sqlite_query($this->db, $this->prepare);
109+
return $this;
110+
}
111+
112+
function last_insert_id() {
113+
return sqlite_last_insert_rowid ($this->db);
114+
}
115+
116+
function rows() {
117+
return sqlite_num_rows($this->query);
118+
}
119+
120+
function getColumns($table) {
121+
return $this->query("PRAGMA table_info($table)")->fetchAll(SQLite::ASSOC);
122+
}
123+
124+
function getTables() {
125+
return $this->query("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")->fetchAll(SQLite::ASSOC);
126+
}
127+
128+
function escape_string($string, $quotestyle='both') {
129+
130+
if( function_exists('sqlite_escape_string') ){
131+
$string = sqlite_escape_string($string);
132+
$string = str_replace("''","'",$string); #- no quote escaped so will work like with no sqlite_escape_string available
133+
}
134+
else{
135+
$escapes = array("\x00", "\x0a", "\x0d", "\x1a", "\x09","\\");
136+
$replace = array('\0', '\n', '\r', '\Z' , '\t', "\\\\");
137+
}
138+
switch(strtolower($quotestyle)){
139+
case 'double':
140+
case 'd':
141+
case '"':
142+
$escapes[] = '"';
143+
$replace[] = '\"';
144+
break;
145+
case 'single':
146+
case 's':
147+
case "'":
148+
$escapes[] = "'";
149+
$replace[] = "''";
150+
break;
151+
case 'both':
152+
case 'b':
153+
case '"\'':
154+
case '\'"':
155+
$escapes[] = '"';
156+
$replace[] = '\"';
157+
$escapes[] = "'";
158+
$replace[] = "''";
159+
break;
160+
}
161+
return str_replace($escapes,$replace,$string);
162+
}
163+
164+
function error($error) {
165+
if(!$this->db) {
166+
return '[ERROR] No Db Handler';
167+
}
168+
if(empty($error)) {
169+
return sqlite_last_error ($this->db);
170+
}
171+
return $error;
172+
}
173+
}
174+
?>

0 commit comments

Comments
 (0)