USE `test`$$
DROP PROCEDURE IF EXISTS `p_getAllTablesCount`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `p_getAllTablesCount`()
BEGIN
DECLARE tableName VARCHAR (100)
DECLARE tablesn VARCHAR (100)
DECLARE tableCount INT
DECLARE stopFlag INT
DECLARE sqlStr VARCHAR(1000)
-- 注意:请修改数据库名称
DECLARE cursor_name CURSOR FOR SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema='test'
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET stopFlag=1
CREATE TABLE IF NOT EXISTS temp_table(table_name VARCHAR(100),table_count VARCHAR(100))
OPEN cursor_name
REPEAT
FETCH cursor_name INTO tableName
SET sqlStr = CONCAT('SELECT COUNT(1) into @tableCount FROM ', tableName)
SELECT sqlStr INTO @sqlStr
-- select @sqlStr
SELECT @tableCount INTO tableCount
BEGIN
PREPARE stepInsertIntoTable FROM @sqlStr
EXECUTE stepInsertIntoTable
END
SET sqlStr = CONCAT('insert into temp_table values(''',CONCAT(tableName),''',''',CONCAT(tableCount),''')')
SELECT sqlStr INTO @sqlStr
BEGIN
PREPARE stepInsertIntoTable FROM @sqlStr
EXECUTE stepInsertIntoTable
END
UNTIL stopFlag END REPEAT
CLOSE cursor_name
SELECT table_name,table_count FROM temp_table ORDER BY table_count DESC
-- PREPARE step FROM @sql1
-- EXECUTE step
DROP TABLE temp_table
END$$
DELIMITER
那很有可能是regdate的格式问题,regdate的格式要和now()返回值的格式一样。在mysql_query($sql)后面加上:
echo
mysql_error()
然后然后就可以看到mysql返回的错误了。
<?php//$conn = mysql_connect('localhost','root','root')
$conn = mysql_connect('127.0.0.1','root','root')
if(!$conn)
{
die(mysql_error())
}
mysql_query("set names 'utf8'")
$select_db = mysql_select_db('test')
if(!$select_db)
{
die(mysql_error())
}
$arr = array()
$res = mysql_query("select * from A ORDER BY ID ASC")
while($row=mysql_fetch_array($res))
{
//$arr[] = array($row['code'],$row['note'])
$arr[] = array('code'=>$row['code'],'note'=>$row['note'])
}
//print_r($arr)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table width="200" border="1">
<tr>
<th>代码</th>
<th>内容</th>
</tr>
<?php for($i=0$i<count($arr)$i++){?>
<tr>
<td><?php //echo $arr[$i][0]
echo $arr[$i]['code']?></td>
<td><?php //echo $arr[$i][1]
echo $arr[$i]['note']?></td>
</tr>
<?php }?>
</table>
</body>
</html>
<?php
mysql_close($conn)
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)