mysql给数据库表批量加表前缀_批量修改mysql数据库表前缀。

无标题文档

分页查询

class page

{

private $pagesize;

public $absolutepage;

private $pagecount;

private $totaINum;

private $prevpage;

private $nextpage;

function page($pagesize,$absolutepage)

{

$this->pagesize=$pagesize;

$this->absolutepage=$absolutepage;

}

public function listinfo()

{

$con=mysql_connect("localhost","root","120911");

if(!$con)

{

die('连接失败:'.mysql_error);

}

if(!mysql_select_db("mydb",$con))

{

die('选择数据库失败:'.mysql_error);

}

$result=mysql_query("select*from Persons");

mysql_close($con);

//所查询表中的总条数

$this->totaINum=mysql_num_rows($result);

//计算总页数

$this->pagecount=(int)(($this->totaINum-1)/($this->pagesize))+1;

//is_numeric检测变量是否为数字.absoulutepage为当前页

if($this->absolutepage==""||!is_numeric($this->absolutepage))

{

$this->absolutepage=1;

}

if($this->absolutepage>$this->pagecount)

{

$this->absolutepage=$this->pagecount;

}

if($this->totaINum>1&&$this->absolutepage>1)

{

$this->prevpage=$this->absolutepage-1;

}

if($this->absolutepage>=1&&$this->absolutepagepagecount)

{

$this->nextpage=$this->absolutepage+1;

}

?>

ID姓名年龄

if(mysql_data_seek($result,($this->absolutepage-1)*$this->pagesize))

{

for($i=0;$ipagesize;$i++)

{

if($info=mysql_fetch_array($result))

{

?>

<?php echo $info["personID"];?><?php echo $info["FirstName"];?><?php echo $info["LastName"];?><?php echo $info["Age"];?>

}

}

}

}

public function toPage()

{

?>

一共<?php echo $this->totaINum ?>个学生,第<?php echo $this->absolutepage?>页/共

<?php echo $this->pagecount?>页:

echo "首页";

echo "上一页";

echo "下一页";

echo "末页";

?>

}

}

//$obj=new page(3,$_GET[absolutepage]);

$obj=new page(3,$_GET['absolutepage']);

$obj->listinfo();

$obj->toPage();

?>

Undefined index: 参数未传过来

Use of undefined constant:书写不规范

mysql_list_tables 这种写法已过时,最新写法

function list_tables($database)

{

$rs = mysql_query("SHOW TABLES FROM $database");

$tables = array();

while ($row = mysql_fetch_row($rs)) {

$tables[] = $row[0];

}

mysql_free_result($rs);

return $tables;

}

/*

$con=mysql_connect("localhost","root","120911");

if(!$con)

{

die("连接失败:".mysql_error());

}

else

{

echo "连接成功!";

}

$result=mysql_query("SHOW TABLES FROM shopdata");

while($row=mysql_fetch_row($result))

{

$data[] = $row[0];

echo $row[0],"
";

}

*/

?>

批量修改mysql数据库表前缀

/*

$dbserver='localhost';

$dbname='shopdata';//数据库名

$dbuser='root';//数据库用户名

$dbpassword='120911';//数据库密码

$old_prefix='ecs_';//数据库表的前缀

$new_prefix='biao_';//数据库表的前缀修改为

function listtable($dbname)

{

$rs = mysql_query("SHOW TABLES FROM shopdata");

return $rs;

}

if (!is_string($dbname) || !is_string($old_prefix)|| !is_string($new_prefix))

{

return false;

}

if (!mysql_connect($dbserver,

$dbuser, $dbpassword))

{

print 'Could not connect to mysql';

exit;

}

//取得数据库内所有的表名

$result =listtable('shopdata');

if (!$result)

{

print "DB Error, could not list tables\n"

;

print 'MySQL Error: ' . mysql_error();

exit;

}

//把表名存进$data

while ($row = mysql_fetch_row($result))

{

$data[] = $row[0];

//echo $row[0],"
";

}

//过滤要修改前缀的表名

foreach($data as $k => $v)

{

$preg = preg_match("/^($old_prefix{1})([a-zA-Z0-9_-]+)/i", //正则表达式匹配

$v, $v1);

if($preg)

{

$tab_name[$k] =$v1[2];

str_replace($old_prefix, '', $v);

}

}

if($preg)

{

//批量重命名

foreach($tab_name as $k => $v)

{//修改表名字符串

$sql = "RENAME TABLE '".$old_prefix.$v."' TO '".$new_prefix.$v."'";

mysql_query($sql);

}

echo ":数据表前缀:".$old_prefix."
"."已经修改为:".$new_prefix."
";

}

else

{

echo "您的数据库表的前缀".$old_prefix."输入错误。请检查相关的数据库表的前缀";

}

*/

?>

批量修改数据库前缀

//设置好相关信息

$dbserver='localhost';//连接的服务器一般为localhost

$dbname='shopdata';//数据库名

$dbuser='root';//数据库用户名

$dbpassword='120911';//数据库密码

$old_prefix='ecs_';//数据库的前缀

$new_prefix='biao_';//数据库的前缀修改为

if ( !is_string($dbname) || !is_string($old_prefix)|| !is_string($new_prefix) )

{

return false;

}

if (!mysql_connect($dbserver, $dbuser, $dbpassword)) {

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;

}

//把表名存进$data

while ($row = mysql_fetch_row($result)) {

$data[] = $row[0];

}

//过滤要修改前缀的表名

foreach($data as $k => $v)

{

$preg = preg_match("/^($old_prefix{1})([a-zA-Z0-9_-]+)/i", $v, $v1);

if($preg)

{

$tab_name[$k] = $v1[2];

//$tab_name[$k] = str_replace($old_prefix, '', $v);

}

}

if($preg)

{

// echo '

';

// print_r($tab_name);

// exit();

//批量重命名

foreach($tab_name as $k => $v)

{

$sql = 'RENAME TABLE `'.$old_prefix.$v.'` TO `'.$new_prefix.$v.'`';

mysql_query($sql);

}

print 数据表前缀:.$old_prefix."
".已经修改为:.$new_prefix."
";

}

else

{ print 您的数据库表的前缀.$old_prefix.输入错误。请检查相关的数据库表的前缀;

if ( mysql_free_result($result) ) {

return true;

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值