我正在使用https://editor.datatables.net/generator/为数据库创建模板以将其集成到我的网站上,我填写了所有字段,下载了模板,将文件放在服务器上,但最后,当我使用db的名称设置config.php文件时,它会给我一个错误。
table.myTable.sql
--
-- Editor SQL for DB table myTable
-- Created by http://editor.datatables.net/generator
--
CREATE TABLE IF NOT EXISTS `myTable` (
`a` int(10) NOT NULL auto_increment,
`b` varchar(255),
`c` varchar(255),
PRIMARY KEY( `id` )
);
table.myTable.php
<?php
/*
* Editor server script for DB table myTable
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// The following statement can be removed after the first run (i.e. the
database
// table has been created). It is a good idea to do this to help improve
// performance.
$db->sql( "CREATE TABLE IF NOT EXISTS `myTable` (
`id` int(10) NOT NULL auto_increment,
`a` varchar(255),
`b` varchar(255),
`c` numeric(9,2),
);" );
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'myTable', 'id' )
->fields(
Field::inst( 'a' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'b' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'c' )
)
->process( $_POST )
->json();
的config.php
<?php if (!defined('DATATABLES')) exit(); // Ensure being used in DataTables
env.
/*
* DB connection script for Editor
* Created by http://editor.datatables.net/generator
*/
// Enable error reporting for debugging (remove for production)
error_reporting(E_ALL);
ini_set('display_errors', '1');
/*
* Edit the following with your database connection options
*/
$sql_details = array(
"type" => "Mysql",
"user" => "root",
"pass" => "",
"host" => "localhost",
"port" => "",
"db" => "myTable",
"dsn" => "charset=utf8"
);
myTable.html
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Table</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs-3.3.7/jq-2.2.4/dt-1.10.15/b-1.3.1/r-2.1.1/se-1.2.2/datatables.min.css">
<link rel="stylesheet" type="text/css" href="css/generator-base.css">
<link rel="stylesheet" type="text/css" href="css/editor.bootstrap.min.css">
<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/v/bs-3.3.7/jq-2.2.4/dt-1.10.15/b-1.3.1/r-2.1.1/se-1.2.2/datatables.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/dataTables.editor.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/editor.bootstrap.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/table.Publications.js"></script>
</head>
<body class="bootstrap">
<div class="container">
<h1>
Table</span>
</h1>
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="myTable" width="100%">
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
</table>
</div>
</body>
</html>
我错过了什么吗?如何在myTable.sql中存储数据?
错误是:
DataTables warning: table id=myTable - An error occurred while connecting to the database 'myTable'. The error reported by the server was: SQLSTATE[HY000] [1049] Unknown database 'myTable'