Adjust the database class table and fields array.

This commit is contained in:
Mark Crane 2012-07-24 05:56:30 +00:00
parent 385876d2a4
commit ccd378e863
1 changed files with 12 additions and 10 deletions

View File

@ -29,12 +29,14 @@ include "root.php";
if (!class_exists('database')) { if (!class_exists('database')) {
class database { class database {
public $db; public $db;
public $driver;
public $type;
public $host;
public $port;
public $name; //database name public $name; //database name
public $username; public $username;
public $password; public $password;
public $result; public $path;
public $type;
public $driver;
public $table; public $table;
public $where; //array public $where; //array
public $order_by; //array public $order_by; //array
@ -44,6 +46,7 @@ include "root.php";
public $fields; public $fields;
public $count; public $count;
public $sql; public $sql;
public $result;
public function connect() { public function connect() {
@ -71,7 +74,6 @@ include "root.php";
if (strlen($db_username) > 0) { $this->username = $db_username; } if (strlen($db_username) > 0) { $this->username = $db_username; }
if (strlen($db_password) > 0) { $this->password = $db_password; } if (strlen($db_password) > 0) { $this->password = $db_password; }
if (strlen($db_path) > 0) { $this->path = $db_path; } if (strlen($db_path) > 0) { $this->path = $db_path; }
if (strlen($db_name) > 0) { $this->name = $db_name; }
} }
if (strlen($this->driver) == 0) { if (strlen($this->driver) == 0) {
$this->driver = $this->type; $this->driver = $this->type;
@ -241,13 +243,13 @@ include "root.php";
$tmp = $prep_statement->fetchAll(PDO::FETCH_NAMED); $tmp = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if ($this->type == "pgsql" || $this->type == "sqlite" || $this->type == "mssql") { if ($this->type == "pgsql" || $this->type == "sqlite" || $this->type == "mssql") {
foreach ($tmp as &$row) { foreach ($tmp as &$row) {
$result['name'][] = $row['name']; $result[]['name'] = $row['name'];
} }
} }
if ($this->type == "mysql") { if ($this->type == "mysql") {
foreach ($tmp as &$row) { foreach ($tmp as &$row) {
$table_array = array_values($row); $table_array = array_values($row);
$result['name'][] = $table_array[0]; $result[]['name'] = $table_array[0];
} }
} }
return $result; return $result;
@ -305,22 +307,22 @@ include "root.php";
//set the list of fields //set the list of fields
if ($this->type == "sqlite") { if ($this->type == "sqlite") {
foreach($table_info as $row) { foreach($table_info as $row) {
$result['name'][] = $row['name']; $result[]['name'] = $row['name'];
} }
} }
if ($this->type == "pgsql") { if ($this->type == "pgsql") {
foreach($table_info as $row) { foreach($table_info as $row) {
$result['name'][] = $row['column_name']; $result[]['name'] = $row['column_name'];
} }
} }
if ($this->type == "mysql") { if ($this->type == "mysql") {
foreach($table_info as $row) { foreach($table_info as $row) {
$result['name'][] = $row['Field']; $result[]['name'] = $row['Field'];
} }
} }
if ($this->type == "mssql") { if ($this->type == "mssql") {
foreach($table_info as $row) { foreach($table_info as $row) {
$result['name'][] = $row['COLUMN_NAME']; $result[]['name'] = $row['COLUMN_NAME'];
} }
} }