我一直得到这个错误,我不太确定为什么这里不工作。
我试图用PHP创建一个数据库,它返回以下错误:
Error creating database: Access denied for user 'scriptcooke'@'10.%' to database 'my_db'
我相信我有正确的证书,但是@10呢?%甚至意味着?
注意:我试图在这里使用w3schools代码示例:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
@10.%
为用户定义中的源主机字段。
问题是:您没有创建新数据库的权限。您使用的用户只能使用自己的数据库;
指子网IP的第一个八位字节。在英语中,它指的是用户正在连接的网络"部分"。尝试@localhost或@.*
<?php
//Create simple connection with no any error.
//connect with no password but.
$con=mysql_connect("localhost","root","");
mysql_select_db("my_db") or die(mysql_error());
//Retrieve all the data from the "example" table
$result = mysql_query("select * from contact LIMIT 0, 30 ")or
die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo "Name: ".$row['Name'];
echo "Email: ".$row['Email'];
mysql_close($con);
?>
首先你需要在mysql中创建数据库的权限。如果你是用户,那么你可以创建mysql数据库。首先要检查数据库是否连接。创建数据库的php代码是:
<?php
$con=mysql_connect('localhost','root','');
if($con)
{
$query=mysql_query('create database new') or die(mysql_error());
$qu=mysql_query('use new');
if($query)
{
echo'Database is created';
}
else
{
echo'Database is not created';
}
}
else
{
echo'The database is not connected';
}
?>
- connect_error) {"连接失败:"。康涅狄格州-> connect_error);}//创建数据库$sql = " Create database myDB";如果($conn->query($sql) === TRUE) {返回"数据库创建成功";} else {echo "创建数据库错误:"。康涅狄格州->错误;}康涅狄格州-> close ();?>