Browse code

Passage en MySQL

schardon authored on 01/05/2020 13:56:02
Showing 1 changed files
... ...
@@ -1,31 +1,39 @@
1 1
 <?php
2 2
 
3 3
 class Database {
4
-  private $_dbfile;
5 4
   private $_dbcnx;
5
+  private $_req = false;
6 6
 
7
-  public function __construct($dbfile) {
8
-    $this->_dbfile = $dbfile;
7
+  public function __construct($dbhost, $dbname, $dblogin, $dbpasswd) {
8
+    $this->_dbcnx = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.';charset=utf8', $dblogin, $dbpasswd);
9
+
10
+/*
9 11
     $this->_dbcnx = false;
10 12
     while(!$this->_dbcnx) {
11 13
       $this->_dbcnx = new SQLite3($this->_dbfile);
12 14
       $this->_dbcnx->busyTimeout(5000);
13 15
     }
16
+*/
14 17
   }
15 18
 
16 19
   public function req($req) {
17
-    return $this->_dbcnx->query($req);
20
+    if($this->_req) $this->_req->closeCursor();
21
+    $this->_req = $this->_dbcnx->query($req);
22
+    return $this->_req;
18 23
   }
19 24
 
20 25
   public function next($dbreq) {
21
-    return $dbreq->fetchArray();
26
+    return $dbreq->fetch();
22 27
   }
23 28
 
24 29
   public function reqFirst($req) {
25
-    return $this->next( $this->req( $req ) );
30
+    $dbreq = $this->req($req);
31
+    if($dbreq)
32
+      return $this->next( $dbreq );
33
+    return false;
26 34
   }
27 35
 }
28 36
 
29
-$db = new Database($racine.'/'.$__CONF['dbfile']);
37
+$db = new Database($__CONF['dbhost'], $__CONF['dbname'], $__CONF['dblogin'], $__CONF['dbpasswd']);
30 38
 
31 39
 ?>
Browse code

Externalisation du systeme de menu commun aux jeux

schardon authored on 27/04/2020 23:08:28
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+class Database {
4
+  private $_dbfile;
5
+  private $_dbcnx;
6
+
7
+  public function __construct($dbfile) {
8
+    $this->_dbfile = $dbfile;
9
+    $this->_dbcnx = false;
10
+    while(!$this->_dbcnx) {
11
+      $this->_dbcnx = new SQLite3($this->_dbfile);
12
+      $this->_dbcnx->busyTimeout(5000);
13
+    }
14
+  }
15
+
16
+  public function req($req) {
17
+    return $this->_dbcnx->query($req);
18
+  }
19
+
20
+  public function next($dbreq) {
21
+    return $dbreq->fetchArray();
22
+  }
23
+
24
+  public function reqFirst($req) {
25
+    return $this->next( $this->req( $req ) );
26
+  }
27
+}
28
+
29
+$db = new Database($racine.'/'.$__CONF['dbfile']);
30
+
31
+?>