每个表都应该有区分
创新互联建站是一家专业提供坡头企业网站建设,专注与成都网站设计、成都网站制作、外贸网站建设、HTML5建站、小程序制作等业务。10年已为坡头众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。
比如结尾_1
_2
_3
,循环sql
替换表结尾的表示,
规律看你的表名了
$data=array();
$sql = "show fields from table";//最主要是这SQL得到全表信息
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
$data[]=$row['Field'];
}
$data数组就是字段名,count($data)就是字段数。
其实很简单啦.
?
$sql = "show fields from [TABLE]";
$data=array();
$query = mysql_query( $sql , $link );
while($row=mysql_fetch_array($query, MYSQL_ASSOC )){
array_push($data,$row);
}
print_R( $data );
?
主要是运行.$sql = "show fields from [TABLE]"这句sql语句就可以了.能得到表全部信息.当然了count( $data )就是字段个数.
mysql_connect("localhost","root","") or die("登陆数据库失败");
mysql_select_db("iPad") or die("连接数据库失败");
mysql_query("set names utf8");
$sql = "ALTER TABLE `表名` ADD `字段名` 数据类型";
mysql_query($sql);
mysql_list_tables 在php5应该支持的,再说,向下兼容的啊帮助文档:例 1397. mysql_list_tables() 例子/b?php
$dbname = 'mysql_dbname';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
print 'Could not connect to mysql';
exit;
}
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
print "Table: $row[0]\n";
}
mysql_free_result($result);
?
function add($name, $type, $size, $defaultvalue = '', $options = '', $title = '', $note = '', $formtype = '', $inputtool = '', $inputlimit = '', $enablehtml = 1, $enablelist = 1, $enablesearch = 0)
{
if(!in_array($type, $this-fieldtypes) || $this-exists($name)) return FALSE;
$size = intval($size);
$fieldsize = $type == 'varchar' ? min($size, 255) : ($type == 'int' ? min($size, 10) : 0);
$fieldtype = strtoupper($type);
if($fieldsize) $fieldtype .= "( $fieldsize )";
$this-db-query("ALTER TABLE $this-table ADD $name $fieldtype NOT NULL");
$this-db-query("INSERT INTO ".TABLE_FIELD."(tablename,name,type,size,defaultvalue,options,title,note,formtype,inputtool,inputlimit,enablehtml,enablelist,enablesearch) VALUES('$this-table','$name','$type','$size','$defaultvalue','$options','$title','$note','$formtype','$inputtool','$inputlimit','$enablehtml','$enablelist','$enablesearch')");
$result = $this-db-affected_rows();
$this-cache();
return $result;
}
function edit($fieldid, $type, $size, $defaultvalue = '', $options = '', $title = '', $note = '', $formtype = '', $inputtool = '', $inputlimit = '', $enablehtml = 1, $enablelist = 1, $enablesearch = 0)
{
if(!in_array($type, $this-fieldtypes)) return FALSE;
$fieldid = intval($fieldid);
$field = $this-get_info($fieldid);
$name = $field['name'];
$size = intval($size);
$fieldsize = $type == 'varchar' ? min($size, 255) : ($type == 'int' ? min($size, 10) : 0);
$fieldtype = strtoupper($type);
if($fieldsize) $fieldtype .= "( $fieldsize )";
$this-db-query("ALTER TABLE `$this-table` CHANGE `$name` `$name` $fieldtype NOT NULL");
$this-db-query("UPDATE ".TABLE_FIELD." SET title='$title',note='$note',type='$type',size='$size',defaultvalue='$defaultvalue',options='$options',formtype='$formtype',inputtool='$inputtool',inputlimit='$inputlimit',enablehtml='$enablehtml',enablelist='$enablelist',enablesearch='$enablesearch' WHERE fieldid=$fieldid");
$result = $this-db-affected_rows();
$this-cache();
return $result;
}
function delete($fieldid)
{
$fieldid = intval($fieldid);
$r = $this-db-get_one("SELECT name FROM ".TABLE_FIELD." WHERE fieldid=$fieldid");
if(!$r) return FALSE;
$name = $r['name'];
$this-db-query("ALTER TABLE $this-table DROP $name");
$this-db-query("DELETE FROM ".TABLE_FIELD." WHERE fieldid=$fieldid");
$result = $this-db-affected_rows();
$this-cache();
return $result;
}
db数据库类去下个phpcms里面的就是上面的是自定义字段的操作函数
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款