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

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

WBOY
Release: 2016-06-13 12:46:53
Original
908 people have browsed it

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

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


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

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