Home > Backend Development > PHP Tutorial > 请帮我看看一段数据库管理的代码为何无效

请帮我看看一段数据库管理的代码为何无效

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:10:02
Original
988 people have browsed it

<?php$dbcon = mysql_connect("localhost","&times;&times;&times;&times;","&times;&times;&times;&times;&times;");if(!$dbcon){    die('could not connect: ' . mysql_error());}echo "mysql connected\n";mysql_query("CREATE DATABASE soap_calc",$dbcon);mysql_select_db("soap_calc",$dbcon);$sql = "CREATE TABLE oils(ID int NOT NULL AUTO_INCREMENT,CN_Name varchar(15),EN_Name varchar(30),SAP decimal(5,3),SAP_NaOH decimal(5,3),Non_Sapon decimal(5,3),Iodine decimal(10,3),PRIMARY KEY (ID))";mysql_query($sql,$dbcon);//read items from file$file = fopen("oiltable", "r");while(!feof($file)){    fscanf($file,"%s %s %s %s %s \n",$CNN,$ENN,$NAOH,$KOH,$INS);    mysql_query("INSERT INTO oils (CN_Name,EN_Name,SAP,SAP_NaOH)                 VALUES ('$CNN','$ENN','$KOH','$NAOH')");}mysql_close($dbcon);echo "db finished\n";?>
Copy after login


我把这个.php文件放到/var/www目录下,然后在浏览器中执行。
echo "mysql connected\n";和echo "db finished\n";都执行了。
但是用phpmyadmin查看数据库发现没有创建soap_calc这个数据库。
我刚开始接触PHP,求指点,谢谢。


回复讨论(解决方案)

[code=php]print_r(mysql_query("CREATE DATABASE soap_calc",$dbcon));[/coder]

看看是不是有错

print_r(mysql_query("CREATE DATABASE soap_calc",$dbcon));[/coder]看看是不是有错
Copy after login
Copy after login


[code=php]print_r(mysql_query("CREATE DATABASE soap_calc",$dbcon));

笔记本键盘老跳光标,打错了,看这段


print_r(mysql_query("CREATE DATABASE soap_calc",$dbcon));[/coder]看看是不是有错
Copy after login
Copy after login


[code=php]print_r(mysql_query("CREATE DATABASE soap_calc",$dbcon));

笔记本键盘老跳光标,打错了,看这段

我添加这条语句后,在浏览器中运行是空白的,原来输出的信息也没有输出了。
后来在echo "mysql connected\n";后添加了flush(), 
输出结果是“mysql connected db finished ”,跟以前一样,
但没有输出mysql_query()的错误信息
不知道如何解释。

mysql_query("CREATE DATABASE soap_calc",$dbcon) or die(mysql_error());
看看,估计是没有权限

mysql_query("CREATE DATABASE soap_calc",$dbcon) or die(mysql_error());
看看,估计是没有权限
的确是权限的问题
我用来登录的用户只有usage权限
刚开始接触php和mysql很多问题都不熟悉,
多谢:)

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