Last night I noticed now Zend IDE has the Data Source Explorer set up like a tree of your database and tables, columns, keys, etc.
I thought that was pretty cool, so I decided to do the same thing.
But with my buddy JSON and his right hand man PHP, we will let Flex come and play with all of us.
This is going to move fast:
First method – Utility method for sending us an array from MySQL.
public function queryToJSON( $sql )
{
$result = mysqli_query ( $this->mysqli, $sql );
while ( $row = mysqli_fetch_assoc ( $result ) )
{
$array [] = $row;
}
return json_encode ( $array );
}Next we are going to start from the bottom up, some of these methods are dummy methods and dont get any data. Because I havent wanted to yet. Triggers Folder
private function tree_tbl_getTriggers( $database, $table )
{
//$triggerArray = $this->queryToARRAY ( "SHOW INDEX FROM $database.$table" );
$triggerFolder = array ( 'label' => 'Triggers', 'children' => array ( $triggerArray ) );
return $triggerFolder;
}Index Folder:
private function tree_tbl_getIndexes( $database, $table )
{
$sql = "SHOW INDEX FROM $database.$table";
$query = mysqli_query ( $this->mysqli, $sql );
$indexArray = array ();
while ( $row = mysqli_fetch_row ( $query ) )
{
if ( $row [ 2 ] !== 'PRIMARY' )
{
$indexArray [] = array (
'label' => $row [ 4 ] . "($row[2])" );
}
}
$indexFolder = array ( 'label' => 'Indexes', 'children' => $indexArray );
return $indexFolder;
}Dependencies Folder:
private function tree_tbl_getDependcenies( $database, $table )
{
$dependArray = array ( 'label' => 'admin table' );
$dependFolder = array ( 'label' => 'Dependencies', 'children' => array ( $dependArray ) );
return $dependFolder;
}Constraints Folder:
private function tree_tbl_getConstraints( $database, $table )
{
$sql = "SHOW INDEX FROM $database.$table";
$result = mysqli_query ( $this->mysqli, $sql );
$constraintArray = array ();
while ( $constraint = mysqli_fetch_assoc ( $result ) )
{
if ( $constraint [ 'Key_name' ] == 'PRIMARY' )
{
$constraintArray = array ( 'label' => $constraint [ 'Key_name' ] );
}
}
$constraintFolder = array ( 'label' => 'Constraints', 'children' => array ( $constraintArray ) );
return $constraintFolder;
}Columns Folder:
private function tree_tbl_getColumns( $database, $table )
{
$sql = "SHOW FIELDS FROM $database.$table";
$query = mysqli_query ( $this->mysqli, $sql );
$columnsArray = array ();
while ( $row = mysqli_fetch_row ( $query ) )
{
$type = strtoupper ( $row [ 1 ] );
$null = '';
if ( $row [ 2 ] == 'YES' )
{
$null = 'Nullable';
}
$type = '[' . $type . ' ' . $null . ']';
$columnsArray [] = array ( 'label' => $row [ 0 ] . ' ' . $type );
}
$columnsFolder = array ( 'label' => 'Columns', 'children' => $columnsArray );
return $columnsFolder;
}Some dummy methods I haven’t finished yet.
Dependencies, Stored Procedures, User Functions, Authorizations, etc. Folders:
private function tree_db_getDependcenies( $database )
{
$dependceniesArray = array ( 'label' => 'Dependcencies', 'children' => array ( 'label' => 'test' ) );
return $dependceniesArray;
}
private function tree_db_getStoredProcs( $database )
{
$storedProcsArray = array ( 'label' => 'Stored Procedures', 'children' => array ( 'label' => 'test' ) );
return $storedProcsArray;
}
private function tree_db_getUserFunctions( $database )
{
}
private function tree_db_getAuthorizations()
{
$authorizationsArray = array ( 'label' => 'Authorization IDs', 'children' => array ( 'label' => 'rfd' ) );
return $authorizationsArray;
}
private function tree_db_getViews( $database )
{
}Tables Folder:
private function tree_db_getTables( $database )
{
//table query
$tableSQL = mysqli_query ( $this->mysqli, "SHOW TABLES FROM $database" );
//create a new array of tables
$tables = array ();
//loop all the results
while ( $table = mysqli_fetch_assoc ( $tableSQL ) )
{
$columns = array ();
$statuss = array ();
$indexes = array ();
//for each table in the result make an array
foreach ( $table as $t_key => $t_value )
{
//get the tables fields for each table
$columns = $this->tree_tbl_getColumns ( $database, $t_value );
//now get the primary key for each table
$constraints = $this->tree_tbl_getConstraints ( $database, $t_value );
//now get the indexes for each table
$indexes = $this->tree_tbl_getIndexes ( $database, $t_value );
//now get the dependencys for each table
$dependicy = $this->tree_tbl_getDependcenies ( $database, $t_value );
//now get the triggers for each table
$triggers = $this->tree_tbl_getTriggers ( $database, $t_value );
}
$columnArr = $columns;
$constraintArr = $constraints;
$indexArr = $indexes;
$dependencyArr = $dependicy;
$triggerArr = $triggers;
$tables [] = array ( 'label' => $t_value, "type" => "table", "icon" => "table", 'children' => array ( $columnArr, $constraintArr, $indexArr, $dependencyArr, $triggerArr ) );
}
$tableFolder [] = array ( 'label' => 'Tables', 'children' => $tables );
return $tableFolder;
}Database Folder:
public function tree_getSchemas()
{
//Database query
$databaseSQL = $this->realQuery ( "SHOW DATABASES" );
//New database array
$databases = array ();
//Loop the query
while ( $database = mysqli_fetch_assoc ( $databaseSQL ) )
{
//Create a new array of tables for each database
$tables = array ();
//$status = array ();
//$size = array ();
foreach ( $database as $key => $value )
{
//Set the table array to get the tbles from the database
$tables = $this->tree_db_getTables ( $value );
//$status = $this->_getTableStatus ( $value );
//$size = $this->_getDatabaseSize ( $value );
}
//Add the tables to the database array
$databases [] = array ( "label" => $value, "data" => $key, "type" => "database", "icon" => "database", "children" => $tables );
}
$databaseFolder [] = array ( 'label' => 'Schemas', 'children' => $databases );
return $databaseFolder;
}Host Folder:
public function tree_getTree()
{
$mysqlVersion = mysqli_get_client_info ( $this->mysqli );
$host = $_SERVER [ 'HTTP_HOST' ] . " (MySQL v. $mysqlVersion )";
$hostArray = array ( 'label' => $host, 'type' => 'server', 'children' => $this->tree_getSchemas () );
$treeArray [] = array ( 'label' => 'SQL Databases', 'type' => 'servers', 'children' => $hostArray );
return $treeArray;
}
I thought that was pretty cool, so I decided to do the same thing.
But with my buddy JSON and his right hand man PHP, we will let Flex come and play with all of us.
This is going to move fast:
First method – Utility method for sending us an array from MySQL.
public function queryToJSON( $sql )
{
$result = mysqli_query ( $this->mysqli, $sql );
while ( $row = mysqli_fetch_assoc ( $result ) )
{
$array [] = $row;
}
return json_encode ( $array );
}Next we are going to start from the bottom up, some of these methods are dummy methods and dont get any data. Because I havent wanted to yet. Triggers Folder
private function tree_tbl_getTriggers( $database, $table )
{
//$triggerArray = $this->queryToARRAY ( "SHOW INDEX FROM $database.$table" );
$triggerFolder = array ( 'label' => 'Triggers', 'children' => array ( $triggerArray ) );
return $triggerFolder;
}Index Folder:
private function tree_tbl_getIndexes( $database, $table )
{
$sql = "SHOW INDEX FROM $database.$table";
$query = mysqli_query ( $this->mysqli, $sql );
$indexArray = array ();
while ( $row = mysqli_fetch_row ( $query ) )
{
if ( $row [ 2 ] !== 'PRIMARY' )
{
$indexArray [] = array (
'label' => $row [ 4 ] . "($row[2])" );
}
}
$indexFolder = array ( 'label' => 'Indexes', 'children' => $indexArray );
return $indexFolder;
}Dependencies Folder:
private function tree_tbl_getDependcenies( $database, $table )
{
$dependArray = array ( 'label' => 'admin table' );
$dependFolder = array ( 'label' => 'Dependencies', 'children' => array ( $dependArray ) );
return $dependFolder;
}Constraints Folder:
private function tree_tbl_getConstraints( $database, $table )
{
$sql = "SHOW INDEX FROM $database.$table";
$result = mysqli_query ( $this->mysqli, $sql );
$constraintArray = array ();
while ( $constraint = mysqli_fetch_assoc ( $result ) )
{
if ( $constraint [ 'Key_name' ] == 'PRIMARY' )
{
$constraintArray = array ( 'label' => $constraint [ 'Key_name' ] );
}
}
$constraintFolder = array ( 'label' => 'Constraints', 'children' => array ( $constraintArray ) );
return $constraintFolder;
}Columns Folder:
private function tree_tbl_getColumns( $database, $table )
{
$sql = "SHOW FIELDS FROM $database.$table";
$query = mysqli_query ( $this->mysqli, $sql );
$columnsArray = array ();
while ( $row = mysqli_fetch_row ( $query ) )
{
$type = strtoupper ( $row [ 1 ] );
$null = '';
if ( $row [ 2 ] == 'YES' )
{
$null = 'Nullable';
}
$type = '[' . $type . ' ' . $null . ']';
$columnsArray [] = array ( 'label' => $row [ 0 ] . ' ' . $type );
}
$columnsFolder = array ( 'label' => 'Columns', 'children' => $columnsArray );
return $columnsFolder;
}Some dummy methods I haven’t finished yet.
Dependencies, Stored Procedures, User Functions, Authorizations, etc. Folders:
private function tree_db_getDependcenies( $database )
{
$dependceniesArray = array ( 'label' => 'Dependcencies', 'children' => array ( 'label' => 'test' ) );
return $dependceniesArray;
}
private function tree_db_getStoredProcs( $database )
{
$storedProcsArray = array ( 'label' => 'Stored Procedures', 'children' => array ( 'label' => 'test' ) );
return $storedProcsArray;
}
private function tree_db_getUserFunctions( $database )
{
}
private function tree_db_getAuthorizations()
{
$authorizationsArray = array ( 'label' => 'Authorization IDs', 'children' => array ( 'label' => 'rfd' ) );
return $authorizationsArray;
}
private function tree_db_getViews( $database )
{
}Tables Folder:
private function tree_db_getTables( $database )
{
//table query
$tableSQL = mysqli_query ( $this->mysqli, "SHOW TABLES FROM $database" );
//create a new array of tables
$tables = array ();
//loop all the results
while ( $table = mysqli_fetch_assoc ( $tableSQL ) )
{
$columns = array ();
$statuss = array ();
$indexes = array ();
//for each table in the result make an array
foreach ( $table as $t_key => $t_value )
{
//get the tables fields for each table
$columns = $this->tree_tbl_getColumns ( $database, $t_value );
//now get the primary key for each table
$constraints = $this->tree_tbl_getConstraints ( $database, $t_value );
//now get the indexes for each table
$indexes = $this->tree_tbl_getIndexes ( $database, $t_value );
//now get the dependencys for each table
$dependicy = $this->tree_tbl_getDependcenies ( $database, $t_value );
//now get the triggers for each table
$triggers = $this->tree_tbl_getTriggers ( $database, $t_value );
}
$columnArr = $columns;
$constraintArr = $constraints;
$indexArr = $indexes;
$dependencyArr = $dependicy;
$triggerArr = $triggers;
$tables [] = array ( 'label' => $t_value, "type" => "table", "icon" => "table", 'children' => array ( $columnArr, $constraintArr, $indexArr, $dependencyArr, $triggerArr ) );
}
$tableFolder [] = array ( 'label' => 'Tables', 'children' => $tables );
return $tableFolder;
}Database Folder:
public function tree_getSchemas()
{
//Database query
$databaseSQL = $this->realQuery ( "SHOW DATABASES" );
//New database array
$databases = array ();
//Loop the query
while ( $database = mysqli_fetch_assoc ( $databaseSQL ) )
{
//Create a new array of tables for each database
$tables = array ();
//$status = array ();
//$size = array ();
foreach ( $database as $key => $value )
{
//Set the table array to get the tbles from the database
$tables = $this->tree_db_getTables ( $value );
//$status = $this->_getTableStatus ( $value );
//$size = $this->_getDatabaseSize ( $value );
}
//Add the tables to the database array
$databases [] = array ( "label" => $value, "data" => $key, "type" => "database", "icon" => "database", "children" => $tables );
}
$databaseFolder [] = array ( 'label' => 'Schemas', 'children' => $databases );
return $databaseFolder;
}Host Folder:
public function tree_getTree()
{
$mysqlVersion = mysqli_get_client_info ( $this->mysqli );
$host = $_SERVER [ 'HTTP_HOST' ] . " (MySQL v. $mysqlVersion )";
$hostArray = array ( 'label' => $host, 'type' => 'server', 'children' => $this->tree_getSchemas () );
$treeArray [] = array ( 'label' => 'SQL Databases', 'type' => 'servers', 'children' => $hostArray );
return $treeArray;
}
发表评论
-
解决MySQL error 1036: table is read only
2011-05-05 22:37 1411改变数据库文件的宿主权限 sudo chown -R mysq ... -
VMware中去掉Linux报警声
2010-05-05 13:09 805将/etc/inputrc中的set bell-style n ... -
Ajax传递数据对加号变空格的处理
2010-01-26 15:11 3107采用Ajax传递数据时,通常会将数据整理为data=" ... -
MySQL 字符串函数大全
2009-12-18 17:29 1220DING | TRAILING] [remstr] FROM] ... -
sybase字符串函数
2009-12-18 12:56 1999长度和语法分析 datalength(char_expr) ... -
json转为java的vo对象
2009-12-17 11:29 6485String str = "[{'name':'he ... -
Java 防SQL 注入函数
2009-12-09 16:34 899看了网上的几个版本,感觉比较别扭,为何不直接用replaceA ... -
Spring启动异常
2009-11-29 22:53 0Spring启动异常: cvc-elt.1: Cannot f ... -
Class IOUtils
2009-11-26 09:03 1108public class IOUtilsextends jav ... -
org.apache.commons.io使用实例
2009-11-26 09:01 26861.文件内容拷贝: import java.io.File; ... -
Firefox 取 TextArea的值
2009-11-06 16:34 848用value代替innerHTML才取的到刚输入的值。 之前竟 ... -
Apache配置Weblogic
2009-10-28 09:21 1546LoadModule weblogic_module modu ... -
logic:itertae标签的使用
2009-10-20 00:37 703相关文章: Struts1.2.4 ... -
Struts多行提交
2009-10-19 16:38 1014ActionForm: public List checkRe ... -
ibatis批量Update
2009-10-19 16:33 2498public boolean updateCheckRus ...
相关推荐
而JSON Schema则是一个JSON格式的规范,用于定义JSON数据的结构和限制,类似于XML Schema,它为JSON数据提供了验证规则,确保数据的准确性和一致性。 在JavaScript开发中,有时我们需要将JSON对象转换为JSON Schema...
JSON Schema 规范(中文版) JSON Schema 是一种强大的工具,用于验证 JSON 数据结构。Schema 可以理解为模式或者规则。在学习 JSON Schema 时,需要理解什么是模式, JSON Schema 的基本类型,如何使用 JSON ...
Java Bean转换为Json Schema是一种常见的数据转换操作,特别是在开发基于RESTful API的Web服务时,因为JSON Schema提供了数据验证和文档化的功能。Java Bean是Java编程中的一个概念,它是一类具有特定规则的POJO...
JSON Schema 是一个JSON格式的规范,用于定义JSON数据的结构和限制,类似于XML Schema和DTD(文档类型定义)。它提供了一种验证JSON数据是否符合预定义规则的方法,这对于API开发、数据交换和JSON数据存储非常有用。...
JSON Schema 是一种JSON格式的规范,用于定义JSON数据的结构和限制,类似于XML Schema和DTD(文档类型定义)。它在API开发、数据验证、数据交换等场景中扮演着重要角色,确保了数据的一致性和准确性。`json-schema-...
`react-jsonschema-form`是一个非常有用的库,它允许开发者基于JSONSchema标准来创建复杂的Web表单。这个库大大简化了表单的创建、验证和管理,使得在React应用程序中实现动态和数据驱动的表单变得轻而易举。 标题...
### JSON Schema验证规范详解 #### 一、简介 JSON Schema是一种使用JSON来描述其他JSON数据结构的方法。它不仅能够帮助开发者定义数据结构的格式,还能确保数据的有效性和一致性。JSON Schema的一个重要应用就是...
JSON Schema是一种JSON格式的规范,用于验证JSON数据是否符合预设的结构规则,而`go-jsonschema`这个库则将这个验证规则转换成了Go代码,使得在Go项目中处理符合JSON Schema的数据变得更加方便和安全。 在Go语言中...
JSON Schema是一种JSON格式的规范,用于定义JSON数据的结构和限制。它类似于XML Schema和DTD(文档类型定义),为JSON提供了验证和约束的能力。在TypeScript中,typing或类型定义文件(.d.ts)用于提供静态类型检查...
JSON Schema是一种JSON格式的规范,用于定义JSON数据的结构和限制。它类似于XML Schema和DTD(文档类型定义),为JSON数据提供了验证规则,确保数据符合特定的格式和约束。在处理JSON数据时,JSON Schema可以作为强...
本文将深入探讨如何使用Vue.js构建一个基于JSON Schema的可视化编辑器,该编辑器能根据JSON Schema自动生成用户界面。 一、Vue.js基础知识 Vue.js是一个渐进式的JavaScript框架,它允许开发者通过声明式渲染数据到...
### JSON-Schema定义规范 #### 前言 在现代软件开发中,数据交换与处理是必不可少的一部分。随着Web服务的普及以及API的发展,JSON(JavaScript Object Notation)作为一种轻量级的数据交换格式,因其简单易读且...
**PyPI 官网下载 | jsonschema-0.4.tar.gz** 在Python的世界里,`PyPI`(Python Package Index)是官方的第三方Python软件包仓库,它为开发者提供了发布和分享自己创建的Python模块、库等资源的平台。用户可以通过`...
JSON Schema 是一种强大的工具,用于在开发和测试过程中对 JSON 数据进行校验。它提供了一种规范化的语言,用于定义 JSON 数据的结构和约束,确保输入或输出的数据符合预期的格式。以下是对 JSON Schema 在开发和...
JSON Schema是一种JSON格式的规范,用于定义JSON数据的结构和限制,类似于XML Schema在XML中的作用。它提供了验证JSON数据是否符合预定义规则的能力,确保数据的准确性和一致性,广泛应用于API开发、数据验证和文档...
JSON Schema是JSON的一个规范,用于定义JSON数据的结构和限制,类似于XML Schema。它为JSON提供了验证规则,确保数据符合预设的标准,这对于数据交换和API设计至关重要。在PHP中,我们有时需要对JSON数据进行校验,...
jsonschema-generator最新源代码jsonschema-generator最新源代码jsonschema-generator最新源代码jsonschema-generator最新源代码jsonschema-generator最新源代码jsonschema-generator最新源代码jsonschema-generator...
"前端开源库-raml-jsonschema-expander"是一个专为前端开发设计的工具,它专注于处理RAML(RESTful API Modeling Language)和JSON Schema之间的交互。 RAML是一种简洁且强大的方式,用于定义RESTful API的结构、...
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:jsonschema-4.0.0a1-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
基于 Vue 的高效易用的 json-schema 编辑器。支持自定义属性,满足特殊的需求。传入一个默认的树节点,用来接收编辑后的json schema结果