php動態建立mysql資料表

2021-10-06 11:24:42 字數 1127 閱讀 7487

一、mysql建立資料表的語句

//其中id,question_no等均為需要建立的資料庫表的語句;

create table if not exists `表名`(

id int primary key auto_increment not null

, question_no int not null

, one_class varchar

(255),

two_class varchar

(255),

question_types varchar

(255),

select_question_types varchar

(255),

question_stem longtext,

options longtext,

score varchar(20

),answer varchar(20

),analysis longtext,

stem_remark varchar

(255),

answer_remark varchar

(255))

engine

= innodb default

charset

= utf8;

二、與框架thinkphp配合使用

public

function

createdatabase

($database

)catch

(exception $e

)}

注意:在與框架配合使用的時候應該注意的是:db::execute($sql)執行的結果返回的總是為0,也就是建立失敗,但這個時候資料表已經建立成功了,所以我們通過try{}catch(exception $e){}來進行處理結果。

建立mysql資料表

mysql建表語句 create table if not exists db name.table name colunum1 date not null comment 列欄位說明 colunum2 int 11 not null comment 列欄位說明 colunum3 int 11 no...

MYSQL 建立資料表

rdbms即關聯式資料庫管理系統 relational database management system 的特點 rdbms術語 資料庫 一些關聯的表的集合 資料表 資料的矩陣。等同於簡單的電子 列 同一類資料 行 一組相關資料,稱為乙個記錄 冗餘 儲存量被資料,使系統速度更快。主鍵 唯一。外來...

MySQL 建立資料表

建立mysql資料表需要以下資訊 以下為建立mysql資料表的sql通用語法 create table table name column name column type 以下例子將在 runoob 資料庫中建立資料表runoob tbl runoob tbl runoob id int not ...