无法使用PHP创建数据库,并且我的语法正确 [英] can not create a database with PHP and my syntax is correct
问题描述
怎么不能在phpMyAdmin上创建数据库?我连接到PHP就很好了,没有错误消息.但是,当我尝试创建一个数据库(例如phpMyAdmin)时,我总是收到错误消息.如果有问题,我将在页面上放置一个<form>
并提交到我的数据库代码所在的second.php
文件中(以下显示second.php
).
我几乎试图在phpMyAdmin中显示数据库,但是什么都没有显示:
<html>
<body>
<?php
$con = mysqli_connect("localhost", "user", "password");
if(!$con){
echo "could not connect";
} else {
echo "good connection";
}
//creation of database
$sql= 'CREATE DATABASE project';
if(mysql_query($sql,$con)){
echo 'DB created succesfully';
} else {
echo 'error creating DB' . mysql_errno();
}
?>
</body>
</html>
一个问题是您与mysql i
连接并且在其余时间都在使用mysql.选择1个库(不是mysql),并仅使用它.
if(mysqli_query($con, $sql)){
和
echo 'error creating DB' . mysqli_error($con);
How is it is can not create a database on phpMyAdmin? I connect to PHP just fine, no error message. But when I am trying to create a database so phpMyAdmin, I keep getting error. In case it matters I have one page with a <form>
and has a submit to my second.php
file where my database code is (second.php
is shown below).
I am pretty much trying to display the database in phpMyAdmin but nothing shows up:
<html>
<body>
<?php
$con = mysqli_connect("localhost", "user", "password");
if(!$con){
echo "could not connect";
} else {
echo "good connection";
}
//creation of database
$sql= 'CREATE DATABASE project';
if(mysql_query($sql,$con)){
echo 'DB created succesfully';
} else {
echo 'error creating DB' . mysql_errno();
}
?>
</body>
</html>
One issue is you connected with mysqli
and are using mysql the rest of the time. Pick 1 (not mysql) library and use only that.
if(mysqli_query($con, $sql)){
and
echo 'error creating DB' . mysqli_error($con);
这篇关于无法使用PHP创建数据库,并且我的语法正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!