Home  >  Article  >  Backend Development  >  PHP能连接数据库但是不能create database,如何解决

PHP能连接数据库但是不能create database,如何解决

WBOY
WBOYOriginal
2016-06-13 13:22:581055browse

PHP能连接数据库但是不能create database,怎么解决?
先贴代码:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $con = mysql_connect("localhost");
if (!$con)
{
    die('Could not connect: ' . mysql_errno());
}
else
{
    echo "success" . "<br />";
}

if (mysql_query("CREATE DATABASE hello", $con))
{
    echo "Database created";
}
else
{
    echo "ERROR";
}

mysql_close($con);

?>


这段代码,我在zend下编写,运行环境是WAMP,运行结果是
success
ERROR

这意味着连接数据库没问题,但是执行CREATE DATABASE hello出错了。想不明白是怎么回事,求教一下大家。

------解决方案--------------------
看看有没权限创建数据库
------解决方案--------------------
你把 echo "ERROR";
改成 echo mysql_error();

就不要什么“意味着”了
Statement:
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