Formating
This commit is contained in:
parent
b99a29ac86
commit
00322f7da8
1 changed files with 274 additions and 261 deletions
45
c.php
45
c.php
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class connector{
|
class connector
|
||||||
|
{
|
||||||
public $action;
|
public $action;
|
||||||
|
|
||||||
public $server;
|
public $server;
|
||||||
|
@ -12,20 +13,21 @@
|
||||||
private $link;
|
private $link;
|
||||||
private $is_connected;
|
private $is_connected;
|
||||||
|
|
||||||
function connector($user, $password, $server){
|
function connector($user, $password, $server)
|
||||||
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->is_connected = false;
|
$this->is_connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect(){
|
function connect()
|
||||||
|
{
|
||||||
if (!$this->is_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();
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$this->is_connected = true;
|
$this->is_connected = true;
|
||||||
mysql_set_charset("utf8");
|
mysql_set_charset("utf8");
|
||||||
return 'OK';
|
return 'OK';
|
||||||
|
@ -33,13 +35,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectDb($database){
|
function selectDb($database)
|
||||||
|
{
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
|
|
||||||
mysql_select_db($this->database);
|
mysql_select_db($this->database);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbList(){
|
function dbList()
|
||||||
|
{
|
||||||
$db_list = mysql_list_dbs($this->link);
|
$db_list = mysql_list_dbs($this->link);
|
||||||
|
|
||||||
for ($i = 0; $row = mysql_fetch_object($db_list); $i++)
|
for ($i = 0; $row = mysql_fetch_object($db_list); $i++)
|
||||||
|
@ -48,7 +52,8 @@
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tableList($database){
|
function tableList($database)
|
||||||
|
{
|
||||||
$result = mysql_list_tables($database);
|
$result = mysql_list_tables($database);
|
||||||
$num_rows = mysql_num_rows($result);
|
$num_rows = mysql_num_rows($result);
|
||||||
|
|
||||||
|
@ -58,7 +63,8 @@
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($query){
|
function query($query)
|
||||||
|
{
|
||||||
$result_id = mysql_query($query);
|
$result_id = mysql_query($query);
|
||||||
|
|
||||||
if (!$result_id) {
|
if (!$result_id) {
|
||||||
|
@ -83,12 +89,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function disconnect(){
|
function disconnect()
|
||||||
|
{
|
||||||
if ($this->link)
|
if ($this->link)
|
||||||
mysql_close($this->link);
|
mysql_close($this->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectTable($table, $start, $limit){
|
function selectTable($table, $start, $limit)
|
||||||
|
{
|
||||||
$query = "SELECT * FROM `$table` LIMIT $start, $limit";
|
$query = "SELECT * FROM `$table` LIMIT $start, $limit";
|
||||||
$result_id = mysql_query($query);
|
$result_id = mysql_query($query);
|
||||||
|
|
||||||
|
@ -98,7 +106,8 @@
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fieldList($table){
|
function fieldList($table)
|
||||||
|
{
|
||||||
$result_id = mysql_list_fields($this->database, $table);
|
$result_id = mysql_list_fields($this->database, $table);
|
||||||
|
|
||||||
$numOfCols = mysql_num_fields($result_id);
|
$numOfCols = mysql_num_fields($result_id);
|
||||||
|
@ -108,14 +117,16 @@
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function numRows($table){
|
function numRows($table)
|
||||||
|
{
|
||||||
$result_id = mysql_query("SELECT COUNT(*) as total_count FROM `$table`");
|
$result_id = mysql_query("SELECT COUNT(*) as total_count FROM `$table`");
|
||||||
|
|
||||||
$ret = mysql_fetch_object($result_id);
|
$ret = mysql_fetch_object($result_id);
|
||||||
return $ret->total_count;
|
return $ret->total_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateElement($table, $headerJSON, $oldValuesJSON, $newValuesJSON){
|
function updateElement($table, $headerJSON, $oldValuesJSON, $newValuesJSON)
|
||||||
|
{
|
||||||
$header = json_decode($headerJSON);
|
$header = json_decode($headerJSON);
|
||||||
$oldValues = json_decode($oldValuesJSON);
|
$oldValues = json_decode($oldValuesJSON);
|
||||||
$newValues = json_decode($newValuesJSON);
|
$newValues = json_decode($newValuesJSON);
|
||||||
|
@ -144,7 +155,8 @@
|
||||||
echo $info;
|
echo $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addElement($table, $headerJSON, $valuesJSON){
|
function addElement($table, $headerJSON, $valuesJSON)
|
||||||
|
{
|
||||||
$header = json_decode($headerJSON);
|
$header = json_decode($headerJSON);
|
||||||
$values = json_decode($valuesJSON);
|
$values = json_decode($valuesJSON);
|
||||||
$query = "INSERT INTO `$table` (";
|
$query = "INSERT INTO `$table` (";
|
||||||
|
@ -174,7 +186,8 @@
|
||||||
echo $info;
|
echo $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeElement($table, $headerJSON, $valuesJSON){
|
function removeElement($table, $headerJSON, $valuesJSON)
|
||||||
|
{
|
||||||
$header = json_decode($headerJSON);
|
$header = json_decode($headerJSON);
|
||||||
$values = json_decode($valuesJSON);
|
$values = json_decode($valuesJSON);
|
||||||
$query = "DELETE FROM `$table` WHERE (";
|
$query = "DELETE FROM `$table` WHERE (";
|
||||||
|
|
Loading…
Reference in a new issue