Implementation of getrows

This commit is contained in:
Przemek Grondek 2014-07-17 15:10:15 +02:00
parent 46760ff750
commit e876291afe

14
c.php
View File

@ -20,7 +20,7 @@
} }
function connect(){ function connect(){
if(!$this->connected){ if(!$this->is_connected){
$this->link = @mysql_connect($this->server, $this->user, $this->password); $this->link = @mysql_connect($this->server, $this->user, $this->password);
if(!$this->link){ if(!$this->link){
return 'CANNOT connect: '.mysql_error(); return 'CANNOT connect: '.mysql_error();
@ -67,8 +67,8 @@
mysql_close($this->link); mysql_close($this->link);
} }
function selectTable($table){ function selectTable($table, $start, $limit){
$query = "SELECT * FROM `$table`"; $query = "SELECT * FROM `$table` LIMIT $start, $limit";
$result_id = mysql_query($query); $result_id = mysql_query($query);
for($i=0;$row=mysql_fetch_row($result_id);$i++) for($i=0;$row=mysql_fetch_row($result_id);$i++)
@ -96,7 +96,8 @@
$database = $_GET['d']; $database = $_GET['d'];
$table = $_GET['t']; $table = $_GET['t'];
$start = $_GET['s'];
$limit = $_GET['l'];
$query = $_GET['q']; $query = $_GET['q'];
if(($user == null) || ($password == null) || ($action == null)) if(($user == null) || ($password == null) || ($action == null))
@ -130,11 +131,10 @@
$con->connect(); $con->connect();
$con->query($query); $con->query($query);
break; break;
case "select": case "getrows":
$con->connect(); $con->connect();
$con->selectDb($database); $con->selectDb($database);
print_r($con->fieldList($table)); echo json_encode($con->selectTable($table, $start, $limit));
print_r($con->selectTable($table));
break; break;
} }