chinese character can't be table column name.
chinese character can't be table column name.
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
{"fieldErrors":[],"error":"An SQL error occurred: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens","data":[],"ipOpts":[],"cancelled":[],"debug":[{"query":"SELECT ID
as 'ID' FROM aaa
WHERE ID
= :where_0 ","bindings":[{"name":":where_0","value":"3","type":null}]},{"query":"UPDATE aaa
SET Avatar
= :Avatar, Name
= :Name, \u5730\u5740
= :\u5730\u5740 WHERE ID
= :where_0 ","bindings":[{"name":":Avatar","value":"68e1684d-0af7-44ab-8a5d-db72d26b95d08373945243958866952.jpg","type":null},{"name":":Name","value":"ddd","type":null},{"name":":\u5730\u5740","value":"gggg","type":null},{"name":":where_0","value":"3","type":null}]}]}
Description of problem:
I am newbee of the Editor, I have succesed make column dynamic, however, there is problem when my table's columns cotain chinese character, the problems were accounted in New insert and Edit.
Anyway, when I tried Editor table generator (as shown in pic) with chinese character column, it remind me "SQL column name: Not set"
It is running well when all columns are English character, May I know how to solve it?
Thanks.
Replies
Hi,
If you click on the red text just below the entry, you will get the option of setting the SQL column name, which I think will need to be ASCII (based on the limits of MySQL).
Allan
I've succes made SQL column name: 中文, however, when I click run, it shows
Database column names must only contain letters, numbers, underscores or dashes.
Anythings I am doing wrong?
It looks like our validation might be somewhat too strict when automatically generating a column name.
As a workaround at the moment, until I fix this, if you use ASCII character, download the package and then modify the HTML (and SQL / PHP if you want to change the column names in the db as well) then that should work.
Allan
Hi Allan
I still not figure out how to NEW/Edit with chinese column name, attached pls find chromo tool (initialer) for the normal english column edit (long one) and chinese column edit (short one), it seems it is problem come from js, thanks.
Can you show me your PHP and give me a link to your page please?
Thanks,
Allan
Dear Allan
Here is Javascript / output html ran by php
```php
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
$htmlHeader='<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="https://www.datatables.net/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, user-scalable=no">
<title>ecotag.hk</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.0/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.0.0/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.3/css/select.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.1.1/css/dataTables.dateTime.min.css">
<link rel="stylesheet" type="text/css" href="./css/editor.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="./resources/syntax/shCore.css">
<link rel="stylesheet" type="text/css" href="./resources/demo.css">
<style type="text/css" class="init"> </style>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.11.0/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.0.0/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/datetime/1.1.1/js/dataTables.dateTime.min.js"></script>
<script type="text/javascript" language="javascript" src="./js/dataTables.editor.js"></script>
<script type="text/javascript" language="javascript" src="./resources/syntax/shCore.js"></script>
<script type="text/javascript" language="javascript" src="./resources/demo.js"></script>
<script type="text/javascript" language="javascript" src="./resources/editor-demo.js"></script>';
$htmlHeader2='</head><body class="dt-example php">
<div class="container">';
require "resizeClass.php";
$servername = "localhost";
$username = "XXXXX";
$password = "XXXXXX";
$dbname = "XXXX";
if ($_SERVER['REQUEST_METHOD'] == 'GET'){
$action=$_GET['action'];
$table = $_GET['table'];
$tableparm = $_GET['tableparm'];
}
$avatarfolder='./'.$table.'/avatar';
// for get about $avatarfolder and code, it is reserve for flutter apps.
$echoStringHeader='';
$documentfields='';
$documentColumns='';
$sqlA = "SELECT * from $tableparm order by columnOrder + 0 ASC";
$col=array();
$types=array();
$resultA = $conn->query($sqlA);
if($resultA->num_rows > 0){
while($rowA = $resultA->fetch_assoc()){
}else{
} // end of avatar
$getparm='?table='.$table.'&tableparm='.$tableparm.'&action=GET_ALL';
} // end of num rows >0
for ($j=0; $row = $result->fetch_assoc(); $j++) {
for ($i=0;$i<count($col);$i++){
if($types[$i]=='time'||$types[$i]=='date'||$types[$i]=='timestamp')
$row[$col[$i]]=date("Y-m-d", strtotime($row[$col[$i]]));
if($types[$i]=="avatar"){
$_path='./'.$avatarfolder.'/'.$row[$col[$i]];
$_thumbpath='./'.$avatarfolder.'/'.$row[$col[$i]].'thumb.jpg';
if (!file_exists($_thumbpath)) {
file_put_contents($_thumbpath, base64_decode(resizeImage($_path)));
} // end of thumbpath
}else{
} //end of type[$i]== avatar
$db_data['set'.$i]=$row[$col[$i]];
}//end of for ($i=0;$i<count($col);$i++)
} //end of for loop fetch_assoc()
// Send back the complete records as a json
$conn->close();
$editorset='
$(document).ready(function() { editor = new $.fn.dataTable.Editor( { "ajax": "./controllers/ecotag.php'.$getparm.'", "contentType": "UTF-8", "table": "#'.$table.'", "fields": ['.$documentfields.' ] } ); $("#'.$table.'").DataTable( { dom: "Bfrtip", ajax: { url: "./controllers/ecotag.php'.$getparm.'", type: "POST" }, serverSide: true, columns: ['.$documentColumns.' ], select: true, "contentType": "UTF-8", buttons: [ { extend: "create", editor: editor }, { extend: "edit", editor: editor }, { extend: "remove", editor: editor } ] } ); } );';
echo $htmlHeader.$editorset.$htmlHeader2;
echo '
</div></body> </html>";
<?php > ``` ?>Here is server side script with some php function, filename: ecotag.php
**** kindly help me to check/ findout the problem I got, thank you Allan`
here is config.php
Hi Allan
for server side script ecotag.php, I removed unnecessary code that may help you to review, thx.
Thanks for all the code. A little more I'm afraid - could you show me the rendered Javascript for DataTables / Editor? Even better would be a link to the page as I could diagnose that directly.
Thanks,
Allan
Hi Allan
Yes, kindly help me to diagnose these two links, thanks.
https://www.ecotag.hk/digi/dynamicWebTableEditable_beta.php?table=bbb (normal)
https://www.ecotag.hk/digi/dynamicWebTableEditable_beta.php?table=aaa (problem)
Thanks Allan
Thank you! It looks like it might be a problem with using non-ASCII characters for the PDO bindings:
Could you try the following for me please?
Where
$dbh
is a PDO database handle. If you don't have one already, you could use the one created by Editor -$db->resource()
.My guess is that will give an error.
Thanks,
Allan
Hi Allan
I am not familiar to use PDO, can you provide a php pdo file code for me, thx.
Hi Allan
I got pdo test script online. and I guess it may be php version problem, I now trying to figure out.
Hi Allan
I upgraded php from 7.2.2.4 to 7.3, still not ok,
then 7.4, the result still not OK.
Next step upgrade will be a big change that I am I afraid my source code will be affacted by PHP version 8.0.
it seems it is not come form php version differs.
I am not familiar with PDO, would you provide simple php code for me to running requested test in my server, thanks.
What does that result in? (where
lib/DataTables.php
is the same as what you'd use for your Editor PHP scripts).Allan
HI Allan
I am giving up to findout the non-ASCII code problem.
Currentlly I am setting all column names to set0, set1, set2......... dynamiclly, then use another table as table parm to match back the correct column name, though this I got extra advance, any character, space can be as a title of column name.
There is minor problem, when I do new and edit, the dialog still show set0, set1.... as shown in picture, could you tell me how can I replace these name in New, Edit Dialog, thanks.
Hi Allan
Please close this thread, I just find out by myself, it only need modify label to corresponding value.
Have a nice day, so happy.....
Excellent, glad it's sorted, thanks for posting back,
Colin