php txtsql 说明,PHP学习笔记(2)txtSQL文档错误

PHP学习笔记(2)txtSQL文档错误

次阅读

在使用txtSQL的过程中,发现一处帮助文档错误。

在使用altertable命令改变表名称时,发现如果按照帮助文档所说,使用如下代码无法改变表的名称:

$sql->altertable(array('db'=>$db_name,'table'=>$table_name,'name'=>$table_name,'action'=>'rename table','value'=>array('name'=>$table_rename_name))

后来查阅范例程序,才发现如果修改表名必须使用如下代码才可以,也就是说,第三个参数“name”的值应该是新的表名。不需要设定第五个参数“value”:

$sql->altertable(array('db'=>$db_name,'table'=>$table_name,'name'=>$table_rename_name,'action'=>'rename table')

以下是帮助文档中的描述:

altertable

Purpose: To alter a txtSQL-table's column definitions txtSQL >= 2.2.2 RC2

void altertable ( array ('table' => $table, 'action' => $action, 'name' => $column, 'values' => $values [, 'after' => $afterColumn [, 'db' => $db]]) )

This function will alter a txtSQL-$table's column defintions. It will only work with the specified column, which is $column. The $action can be either

insert- Inserts a new column, $column, and if specified, after the column $afterColumn

modify- Modifies an existing $column

drop- Drops an existing $column

rename col- Renames a $column. Expects array('name' => $newcolname) in the $values

//此句错误

rename table- Renames a $table. Expects array('name' => $newTableName) in the $values

addkey- Sets $column as the primary key ( must be integer and auto_increment ). Expects array('name' => $colName) in the $values

dropkey- Does opposite of 'addkey'

The $values element is an array containing information about the column, it must be in the following format

array( [$colType => $value]... ) unless otherwise noted above

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TXTSQL是一种文本数据库,文件存储方式类似mysql,兼容部分sql语句.   PHP需4.0以上版本才能运行。   官方网站:http://txtsql.com/ txtSQL简单例子(来源:http://smvcn.xhblog.com/archives/2007/259845.shtml)   <?php   include('./txtSQL.class.php');   $sql = new txtSQL('./data');   $sql->connect('root', 'bar');   /*创建数据库   $sql->createdb(array('db' => 'demo')) or die('Error creating txtSQL DB, txtSQL said: '.$sql->get_last_error());   */   /*选择数据库*/   $sql->selectdb ( 'demo' );   /*创建表   $columns = array('id' => array('type' => 'int', 'auto_increment' => 1, 'permanent' => 1 ),   'name' => array('type' => 'string', 'max' => 50),   'email' => array('type' => 'string', 'max' => 50)   );   foreach($columns as $k => $v){   echo "\$colums[$k]=";   foreach($v as $k1 => $v1){   echo "$k1:$v1 ";   }   echo "<br>";   }   $sql->execute('create table',array(   'table' => 'table1',   'columns' => $columns)) or die('建表发生错误:'.$sql->get_last_error());   if($sql->table_exists('table1','demo')){   echo "建表成功";   }else{   echo "建表失败";   }   */   /*插入纪录   $value = array(0 => array('name' => 'abc','email' => 'abc@123.com'),   1 => array('name' => '123','email' => '123@bac.com'),   2 => array('name' => 'df','email' => 'reg@bac.com'),   3 => array('name' => 'trt','email' => 'hgh@bac.com'),   4 => array('name' => 'tyty','email' => 'ytyt@bac.com')   );   for($i=0;$i<5;$i++){   echo "\$value[$i]:";   foreach($value[$i] as $k => $v){   echo "[$k]=$v ";   }   echo "<br>";   }   for($i=0;$i<5;$i++){   if(!$sql->execute('insert',array('table' => 'table1','values' => $value[$i] ))){   die('An error occurred, txtSQL said: '.$sql->get_last_error());   }else{   echo "插入成功<br>";   }   }   */   /*修改表数据   $value = array('name' => 'abc','email' => 'aaa@123.com');   if(!$sql->execute('update',array('table' => 'table1','where' => array('id = 1'),'values' => $value))){   die('An error occurred, txtSQL said: '.$sql->get_last_error());   }else{   echo "修改成功";   }   */   /*删除表内容   $delete = array('table' => 'table1','where' => array('id > 1'));   $delcount = $sql->execute('delete',$delete);   echo $delcount;   */   /*显示表内容*/   $select = array('table' => 'table1','orderby' => array('id','asc')/*,'where' => array('email =~ %bac%'),'limit' => array(0,9)*/);   $data = $sql->execute('select',$select);   echo "<table border=1><tr><th>id</th><th>name</th><th>email</th></tr>";   foreach ( $data as $key => $row )   {   echo "<tr>";   foreach($row as $k => $v){   echo "<td>$v</td>";   }   echo "</tr>";   }   echo "</table>";   echo "表内共有 ".$sql->table_count('table1')." 行<BR>";   /*加入主键   $sql->execute('alter table',array('table' => 'table1','action' => 'addkey','name' => 'id','values' => array('name' => 'id')));   */   echo "最后插入ID号:".$sql->last_insert_id('table1') ;   $sql->disconnect();   ?>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值