Home > Backend Development > PHP Tutorial > php建表不成功,但也没有报错,求解解决办法

php建表不成功,但也没有报错,求解解决办法

WBOY
Release: 2016-06-13 10:17:35
Original
1009 people have browsed it

php建表不成功,但也没有报错,求解

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php //连接数据        $con=mysql_connect("localhost","root","welcome123") or die("无法连接数据库".mysql_error());        //判断是否有my_project数据库        $existDB=mysql_select_db("my_project",$con);        //echo "没有my_project数据库";        if(!$existDB)        {            //创建数据库            $cdatabseSql="Create DATABASE my_project";            mysql_query($cdatabseSql,$con);        }        else        {            echo "有数据库";        }        //判断是否有sendmail表        $row=mysql_query("show databases");        $database=array();        $finddatabase="sendmail";        while ($result=mysql_fetch_array($row,MYSQL_ASSOC))        {            $database[]=$result['Database'];        }        unset($result,$row);                if(!in_array($finddatabase,$database))        {            echo "没有表";                $ctableSql="Create TABLE sendmail (                ID INT AUTO_INCREMENT PRIMARY KEY,                tomail nvarchar(50),                subject nvarchar(50),                message text            )";            mysql_query($ctableSql,$con);        }        else        {            echo "有表";            }        die();?>
Copy after login

页面显示:“没有表”,但执行一次后应该创建表了,我再刷新页面还是显示“没有表”,请各位大虾们帮忙看下神马问题?

------解决方案--------------------
试试:
PHP code
        //连接数据        $con=mysql_connect("localhost","root","welcome123") or die("无法连接数据库".mysql_error());        //判断是否有my_project数据库        $existDB=mysql_select_db("my_project",$con);        //echo "没有my_project数据库";        if(!$existDB)        {            //创建数据库            $cdatabseSql="Create DATABASE my_project";            mysql_query($cdatabseSql,$con);            mysql_select_db("my_project",$con);  //选择数据库        }        else        {            echo "有数据库";        }        //判断是否有sendmail表        $row=mysql_query("show tables");        $database=array();        $finddatabase="sendmail";        while ($result=mysql_fetch_array($row,MYSQL_ASSOC))        {            $database[]=$result['Tables_in_test'];        }        unset($result,$row);                if(!in_array($finddatabase,$database))        {            echo "没有表";                $ctableSql="Create TABLE sendmail (                ID INT AUTO_INCREMENT PRIMARY KEY,                tomail nvarchar(50),                subject nvarchar(50),                message text            )";            mysql_query($ctableSql,$con);        }        else        {            echo "有表";            }        die();<br><font color="#e78608">------解决方案--------------------</font><br>大概这样试试,<br><br>
Copy after login
PHP code
        if(!$existDB)        {            //创建数据库            $cdatabseSql="Create DATABASE my_project";            mysql_query($cdatabseSql,$con);                    mysql_select_db("my_project",$con);//加一句,选择库        }…………        //判断是否有sendmail表        $row = mysql_list_tables("my_project");        $database=array();        $finddatabase="sendmail";        while ($result=mysql_fetch_array($row))        {            $database[]=$result[0];        }        unset($result,$row);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template