【问题标题】:Can't read or write on database using php无法使用 php 读取或写入数据库
【发布时间】:2013-11-05 22:57:28
【问题描述】:

我正在开发一个网站,所以我将我的数据存储在 db4free.net - 免费在线数据库中 - 但我无法读取或写入甚至选择数据库(错误:查询错误:. SELECT 命令拒绝用户''@'localhost' 用于表 'first'),但我尝试使用 heidiSQL - 桌面应用程序通过网络管理数据库 - 它工作正常,我可以选择、插入和删除。 这是我的 php 代码:

$conn=mysqli_connect("db4free.net:3306","usr","pass");
$sql = "select * from test1.first";
$result = mysql_query($sql) or die ("Error in query: $query. ".mysql_error());

有什么帮助吗?

【问题讨论】:

  • 您使用的是mysql_query,但mysqli_connect()(注意i)

标签: php mysql database web-applications web


【解决方案1】:

这对我有用:

$conn=mysql_connect("db4free.net","usr","pass",3306);

【讨论】:

  • 很好,但是您应该使用 MySQLi_ 而不是 MySQL_ --- 更好的是,PDO。
  • @Fred-ii-please 你能告诉我为什么吗?
  • MySQL_ 已弃用,这意味着它将在即将发布的 PHP 版本中删除。同样使用MySQLi_ 更安全,但 PDO 更好/更安全。
  • 看看自己,查看链接php.net/manual/en/function.mysql-query.php 并阅读警告。
猜你喜欢
  • 2020-09-11
  • 2016-09-07
  • 1970-01-01
  • 2022-01-24
  • 2019-10-29
  • 1970-01-01
  • 2018-09-03
  • 2023-02-13
  • 2012-06-22
相关资源
最近更新 更多