我正在尝试将数据列上传到mySQL数据库。以下是遇到问题的代码片段。
cursor = mariadb_connection.cursor()
cursor.execute=("CREATE TABLE IF NOT EXISTS table1 (ts TIMESTAMP, col2 char(10), col3 decimal (7,2), col4 decimal (5,2), col5 decimal (7,2), col6 decimal (5,2))")
sql ="INSERT INTO table1 (ts, col2, col3, col4, col5, col6)"
sql += "VALUES (NULL, %s, %s, %s, %s, %s)"
cursor.execute(sql,(var2, var3, var4, var5, var6))
运行代码时,出现以下错误:
cursor.execute(sql,(var2, var3, var4, var5, var6)) TypeError: 'str' object is not callable
请注意,var2
到var6
是从decimal
个对象转换的str
个对象。
更新:从有问题的行中删除=
后,我现在似乎又出现了另一个错误:mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'ts' in 'field list'.
任何想法我做错了什么?
更新:未知列问题的解决方法是删除现有表,然后再次运行脚本
答案 0 :(得分:1)
从include(WPtest_PLUGIN_PATH.'/admin/includes/dompdf/lib/html5lib/Parser.php');
include(WPtest_PLUGIN_PATH.'/admin/includes/dompdf/lib/php-font-lib/src/FontLib/Autoloader.php');
include(WPtest_PLUGIN_PATH.'/admin/includes/dompdf/lib/php-svg-lib/src/autoload.php');
include(WPtest_PLUGIN_PATH.'/admin/includes/dompdf/src/Autoloader.php');
Dompdf\Autoloader::register();
use Dompdf\Dompdf;
class WPtest_Save_PDF{
//use Dompdf\Dompdf;
function __construct(){
add_shortcode( 'save_me',array($this,'print_callback'));
}
function print_callback(){
if(isset($_GET['print']))
{
$dompdf = new Dompdf();
$dompdf->loadHtml("test");
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
exit();
}
}
}
new WPtest_Save_PDF;
删除=
符号并使用此
cursor.excecute=(...)