Hi all. After years of not using it I am just palying a bit arround with PHP. On some earlier questions about PHP people advised me not to use mysql_ beacause it would likely be removed from the next 5.x version. So they advised me to use mysqli_ or even better to use PDO. I have been doing some testing with PDO but that was all quite simple but now I try to get my head arrount classes and it is breaking me up somehow! In a tutorial I found the following database class:
<?php
2
3 class database {
4
5 var $SQL;
6 var $lastquery;
7 var $count=0;
8
9 function database($database, $server='localhost', $username='root', $password=''){
10 $this->SQL = mysql_connect($server, $username, $password) or die('Error: '.mysql_error());
11 mysql_select_db($database, $this->SQL);
12 }
13
14 function query($query, $return='true'){
15 $this->lastquery = $query;
16 $this->count++;
17 $result = mysql_query($query, $this->SQL) or die('Error with Query('.$query.'): '.mysql_error());
18 if ($return)
19 return $result;
20 }
21
22 function num_rows(&$result){
23 return @mysql_num_rows($result);
24 }
25
26 function fetch_array(&$result){
27 return @mysql_fetch_array($result);
28 }
29
30 function fetch_assoc(&$result){
31 return @mysql_fetch_assoc($result);
32 }
33
34 function insert_id(){
35 return @mysql_insert_id();
36 }
37
38 function disconnect(){
39 mysql_close($this->SQL);
40 }
41
42 function escape(&$string){
43 return mysql_real_escape_string($string);
44 }
45
46 function result($query, $column, $id=0){
47 return mysql_result($query, $id, $column);
48 }
49 }
50 ?>
But I realy have no idea how to convert this all to PDO. Any advise or redirections to good tutorials would be more then welcome.
Thank you in advance