php - 请问如何使用pdo将包含138个数组(如下所示)的php数组发布到mysql?
问题描述
我的数据库代码是:
CREATE TABLE IF NOT EXISTS symptoms_list (
id int(11) NOT NULL,
available_names varchar(255) NOT NULL
PRIMARY KEY (id)
);
我的PHP代码是:
<?php
require 'config.php';
$available_names = array (
array(‘Abdominal pain’, ‘Stomach ache’, ’Stomach trouble’, ‘Painful tommy’, ‘Tommy ache’, ‘Tommy pain’, ‘Belly ache’, ‘Belly pain’, ‘Painful tommy’),
array(‘RUQ abdominal pain’, ‘RUQ pain’, ’Right upper quadrant abdominal pain’, ‘Right upper quadrant pain’, ‘Right hypochondriac pain’ ),
array(‘Epigastric pain’, ’mid-upper abdominal pain’),
array(‘LUQ abdominal pain’, ‘LUQ pain’, ‘Left hypochondriac pain’, ‘Lt upper quadrant abdominal pain’),
array(‘Right Para umbilical pain’, ‘Rt para umbilical pain’, ‘Rt para umbilical pain’, ‘Right para umbilical abdominal pain’, ‘Pain right side of the belly button’),
array(‘Umbilical pain’, ‘Periumbilical abdominal pain’, ‘umbilical pain’, ‘Belly button pain’, ‘Umbilical ache’),
array(‘RLQ abdominal pain’, ‘Rt Lower quadrant abdominal pain’, ‘Right lower quadrant pain’, ‘Right lower quadrant abdominal pain’, ‘RLQ pain’),
array(‘suprapubic pain’, ‘Suprapubic pain’, ‘Pain below the umbilicus’, ‘Pain below the navel’, ‘Pain below the belly button’),
array(‘LLQ abdominal pain’, ‘Lt lower quadrant abdominal pain’, ‘LLQ pain’, ‘LLQ abdominal discomfort’, ‘Left lower quadrant abdominal pain’, ‘Left lower quadrant pain’),
array(‘Back pain’, ‘Pain in the back’, ‘Back ache’, ‘Back discomfort’, ‘Pain at the back’),
array(‘Fatigue’, ‘Easy fatiguability’, ’Lassitude’, ’Tiredness’, ’General weakness’, ’Exhaustion’),
array(‘Chest pain’, ‘Painful chest’, ‘Chest discomfort’, ‘Chest heaviness’),
array(‘Otalgia’, ‘Ear ache’, ’Ear pain’, ‘Ear discomfort’, ‘Painful ear’),
array(‘Otorrhea’, ‘Discharging ear’, ‘Ear discharge’)
);
// STORE ARRAY
$sql = $db->prepare("INSERT INTO symptoms_list (id, available_names) VALUES (:id, :available_names)");
// CONNECT TO DATABASE
try {
$stmt = $pdo->prepare($sql);
// Start Transaction
$stmt = $db->beginTransaction();
$array = json_decode($data, true);
// Insert each record
foreach($data as $insertRow){
// now loop through each inner array to match binded values
foreach($insertRow as $column => $value){
$stmt->bindValue(":{$column}", $value);
}
}
// Execute statement to add to transaction
$stmt->execute();
// Clear statement for next record (not necessary, but good practice)
$stmt = null;
}
// Commit all inserts
$db->commit();
?>
每次我尝试将二维数组发布到 mysql 时,我都会收到错误消息:
“解析错误:语法错误,意外 ';',在第 4 行的 C:\xampp2\htdocs\public\symptoms7.php 中期待 ')'”
解决方案
推荐阅读
- assembly - GAS aarch64 语法获取 .ascii 字符串长度
- django - 如何创建视图类在 django 视图中包含所有功能
- javascript - 使用 jQuery 更新动态加载图像的 SRC 属性
- arrays - 将预处理器宏分配给数组成员时如何避免“预期表达式”错误
- php - laravel 中的 where 子句用于搜索
- javascript - getTheme() 本机基础类型
- python - sys.stdout 只创建一个空文件
- mysql - 如何将 Docker MySQL 映像连接到现有的 Rails 应用程序?
- sql - Crystal 报表 SQL 表达式从 DateTime 列中提取年份
- python - 如何根据布尔索引对列表进行切片