正在将我的站点从 XAMPP 上传到 Apache public 主机
Uploading my site from XAMPP to Apache public host
这是一个一般性问题。
我已经在 xampp 中编译了站点并且它是正确的 运行ning,因为缺乏经验我使用 mysql 函数而不是改进的 mysqli.
在 ecowebhost
网站上上传我的网站不起作用,我已经更改了路径,显然没有发生连接错误。但我仍然无法与我的数据库进行交互。
从站点上看似乎支持 php4 版本,因此我需要重新编译我的网站吗?
这是我正在尝试做的一些示例代码...
<?php
function connectto($tablename){
$db_host = "xxx";
$db_username = "xxx";
$db_pass = "xxx";
$link = mysqli_connect("$db_host","$db_username","$db_pass","$tablename") or die ("Could not connect to MySQL");
// @mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
// @mysql_select_db("$tablename") or die ("No database");
}
?>
谢谢
如果我运行以下
<?php
// connection to database
// include_once "connectto.php";
// connectto('test');
$tablename = "test";
$db_host = "xxx";
$db_username = "xxx";
$db_pass = "xxx";
$link =mysqli_connect("$db_host","$db_username","$db_pass","$tablename")
or die ("Could not connect to MySQL");
if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error());}
else { echo " <br /><br />connection established! <br />";}
?>
出现的唯一错误消息是
无法连接到 MySQL
更新....
我的代码有些工作了,但我正在努力寻找一种方法来在数据库中插入一些值...
<?php
$db_host = "xxxx";
$db_username = "xxxx";
$db_pass = "xxxx";
// $link = mysqli_connect("$db_host","$db_username","$db_pass","cl45-members-7b5") or die ("Could not connect to MySQL");
@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("cl45-members-7b5") or die ("No database");
$sql ="INSERT INTO members (username, email, gps_lat, gps_long, password, skill, skill_rate,) VALUES ('a','2','3','4','5','5','6')";
print '<br /><br /> Great! now you are registered; now update your profile <br />';
mysql_query ("$sql");
print '<br /><br />tutto ok;<br /><br />';
?>
有什么地方是错的吗?我没有找到数据库之类的错误...
你的问题让我有点困惑,但你可以通过以下方式使用 MySQLi 进行连接:
$link = new mysqli($db_host,$db_username,$db_pass,$tablename);
在你的代码中你有
or die ("Could not connect to MySQL");
也就是说,如果您出于某种原因无法连接,请打印出来。您不会获得更多信息,因为您需要包含 $conn->connect_error 例如
if ($link->connect_error) {die ("Failed: " . $link->connect_error);}
你应该得到类似
的结果
$tablename = "test";
$db_host = "xxx";
$db_username = "xxx";
$db_pass = "xxx";
$link = new mysqli($db_host,$db_username,$db_pass,$tablename);
if ($link->connect_error) {
die ("Failed: " . $link->connect_error);
} else {
echo " <br /><br />connection established! <br />";
}
经过一番思考并将问题分解为小子任务后,我相信我设法理解了列表中那个愚蠢的额外逗号阻止了我 运行 该程序,我复制粘贴了一个语法共享在线,现在一切似乎都正常...
结果:
- 检查拼写
- 一个一个地隔离问题...
这是一个一般性问题。 我已经在 xampp 中编译了站点并且它是正确的 运行ning,因为缺乏经验我使用 mysql 函数而不是改进的 mysqli.
在 ecowebhost
网站上上传我的网站不起作用,我已经更改了路径,显然没有发生连接错误。但我仍然无法与我的数据库进行交互。
从站点上看似乎支持 php4 版本,因此我需要重新编译我的网站吗?
这是我正在尝试做的一些示例代码...
<?php
function connectto($tablename){
$db_host = "xxx";
$db_username = "xxx";
$db_pass = "xxx";
$link = mysqli_connect("$db_host","$db_username","$db_pass","$tablename") or die ("Could not connect to MySQL");
// @mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
// @mysql_select_db("$tablename") or die ("No database");
}
?>
谢谢
如果我运行以下
<?php
// connection to database
// include_once "connectto.php";
// connectto('test');
$tablename = "test";
$db_host = "xxx";
$db_username = "xxx";
$db_pass = "xxx";
$link =mysqli_connect("$db_host","$db_username","$db_pass","$tablename")
or die ("Could not connect to MySQL");
if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error());}
else { echo " <br /><br />connection established! <br />";}
?>
出现的唯一错误消息是
无法连接到 MySQL
更新....
我的代码有些工作了,但我正在努力寻找一种方法来在数据库中插入一些值...
<?php
$db_host = "xxxx";
$db_username = "xxxx";
$db_pass = "xxxx";
// $link = mysqli_connect("$db_host","$db_username","$db_pass","cl45-members-7b5") or die ("Could not connect to MySQL");
@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("cl45-members-7b5") or die ("No database");
$sql ="INSERT INTO members (username, email, gps_lat, gps_long, password, skill, skill_rate,) VALUES ('a','2','3','4','5','5','6')";
print '<br /><br /> Great! now you are registered; now update your profile <br />';
mysql_query ("$sql");
print '<br /><br />tutto ok;<br /><br />';
?>
有什么地方是错的吗?我没有找到数据库之类的错误...
你的问题让我有点困惑,但你可以通过以下方式使用 MySQLi 进行连接:
$link = new mysqli($db_host,$db_username,$db_pass,$tablename);
在你的代码中你有
or die ("Could not connect to MySQL");
也就是说,如果您出于某种原因无法连接,请打印出来。您不会获得更多信息,因为您需要包含 $conn->connect_error 例如
if ($link->connect_error) {die ("Failed: " . $link->connect_error);}
你应该得到类似
的结果$tablename = "test";
$db_host = "xxx";
$db_username = "xxx";
$db_pass = "xxx";
$link = new mysqli($db_host,$db_username,$db_pass,$tablename);
if ($link->connect_error) {
die ("Failed: " . $link->connect_error);
} else {
echo " <br /><br />connection established! <br />";
}
经过一番思考并将问题分解为小子任务后,我相信我设法理解了列表中那个愚蠢的额外逗号阻止了我 运行 该程序,我复制粘贴了一个语法共享在线,现在一切似乎都正常...
结果: - 检查拼写 - 一个一个地隔离问题...