Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 918937e

Browse files
author
Bastien Crettenand
authored
Feature composer (#7)
* Create composer.json * add basic configuration composer * Update slsql.php * Remove src files * Add src files * Update Slsql.php * Update composer.json * Update Model * Change config concept * Fix : namespace problems
1 parent 0d5c335 commit 918937e

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

src/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php namespace slsql;
2+
3+
class Config
4+
{
5+
const dbType = 'mysql',
6+
dbName = 'Default',
7+
host = '127.0.0.1:3306',
8+
user = 'root',
9+
password = '';
10+
}

src/model/model.php renamed to src/Model/Model.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace slsql\Model;
22

3+
use slsql\Slsql\Slsql;
4+
35
/*
46
* WTFPL License (http://www.wtfpl.net/) - https: //github.com/CrBast/PHP-SQL_SimpleLife/blob/master/LICENSE
57
*
File renamed without changes.
File renamed without changes.

src/slsql/slsql.php renamed to src/Slsql/Slsql.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<?php namespace slqsl\slqsl;
1+
<?php namespace slsql\Slsql;
2+
3+
use slsql\Config;
4+
use \Error;
5+
use \PDO;
26

37
/**
48
* WTFPL License (http://www.wtfpl.net/) - https: //github.com/CrBast/PHP-SQL_SimpleLife/blob/master/LICENSE
@@ -114,7 +118,7 @@ public function createDB()
114118

115119
/**
116120
* Send Request.
117-
* the parameters are in the .env file
121+
* the parameters are in the Config class file (slsql\Config)
118122
*
119123
* Return :
120124
* [value] = result,
@@ -124,7 +128,7 @@ public function createDB()
124128
public static function go($request, $array = array())
125129
{
126130
try {
127-
$db = slsql::getPDO();
131+
$db = Slsql::getPDO();
128132
$stmt = $db->prepare($request);
129133
$stmt->execute($array);
130134
//var_dump($stmt);
@@ -137,7 +141,7 @@ public static function go($request, $array = array())
137141

138142
/**
139143
* Send Transaction.
140-
* the parameters are in the .env file
144+
* the parameters are in the Config class file (slsql\Config)
141145
*
142146
* Return :
143147
* [value] = result,
@@ -146,7 +150,7 @@ public static function go($request, $array = array())
146150
*/
147151
public static function goT(SLTransaction $trans)
148152
{
149-
$db = slsql::getPDO();
153+
$db = Slsql::getPDO();
150154
try {
151155
$db->beginTransaction();
152156
foreach ($trans->get() as $transaction) {
@@ -164,13 +168,11 @@ public static function goT(SLTransaction $trans)
164168

165169
private static function getPDO()
166170
{
167-
try {
168-
require '../.env';
169-
} catch (Exception $e) {
170-
throw new Error("Error Processing Request");
171+
if (!class_exists("\slsql\Config")) {
172+
throw new Error("Cannot find <\slsql\Config>");
171173
}
172174
try {
173-
$db = new PDO($env['DBType'] . ':dbname=' . $env['DBName'] . ';host=' . $env['Host'], $env['User'], $env['Password']);
175+
$db = new PDO(Config::dbType . ':dbname=' . Config::dbName . ';host=' . Config::host, Config::user, Config::password);
174176
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
175177
return $db;
176178
} catch (PDOException $e) {
@@ -195,7 +197,7 @@ public function get()
195197

196198
public function go()
197199
{
198-
return slsql::goT($this);
200+
return Slsql::goT($this);
199201
}
200202
}
201203

File renamed without changes.

src/example.env

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)