如果文件扩展名从 html 重写为 php,PHP 函数 mysql_connect() 不起作用

发布于 2024-09-15 10:20:29 字数 895 浏览 0 评论 0原文

我有一个 html 文件,里面有 php 代码。它包含连接到 mysql 数据库的代码。

当我运行它时,它返回一个错误:

Fatal error: Call to undefined function: mysql_connect() 

如果文件扩展名是 php,则一切正常。

另外,只需提及使用 .htaccess 我重写了文件扩展名。

还有一些功能,例如 include 和 echo 工作正常。

你能帮我解决这个问题吗?

更新:这是 .htaccess 文件:

RewriteEngine On
RewriteBase /

RewriteRule ^item/(.*) item.html/$1
RewriteRule ^page/(.*) page.html/$1
RewriteRule ^page2/(.*) page2.html/$1
RewriteRule ^browse/(.*) browse.html/$1

RewriteRule ^(.*).txt /page/error.html

ErrorDocument 400 /page/error.html
ErrorDocument 401 /page/error.html
ErrorDocument 403 /page/error.html
ErrorDocument 404 /page/error.html
ErrorDocument 500 /page/error.html
DirectoryIndex index.html index.php index.php3 index.htm index.html.var
AddHandler application/x-httpd-php .html

I have html file with php code in it. It contains code to connect to mysql database.

When i run it, it returns me an error:

Fatal error: Call to undefined function: mysql_connect() 

Everything works fine if file extension is php.

Also, just to mention that using .htaccess I have rewritten file extension.

Also some functions, like include and echo work fine.

Can you help me please how to handle this?

Update: Here is the .htaccess file:

RewriteEngine On
RewriteBase /

RewriteRule ^item/(.*) item.html/$1
RewriteRule ^page/(.*) page.html/$1
RewriteRule ^page2/(.*) page2.html/$1
RewriteRule ^browse/(.*) browse.html/$1

RewriteRule ^(.*).txt /page/error.html

ErrorDocument 400 /page/error.html
ErrorDocument 401 /page/error.html
ErrorDocument 403 /page/error.html
ErrorDocument 404 /page/error.html
ErrorDocument 500 /page/error.html
DirectoryIndex index.html index.php index.php3 index.htm index.html.var
AddHandler application/x-httpd-php .html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

年华零落成诗 2024-09-22 10:20:29

在两个文件中运行 phpinfo() 并查看。
将有 2 个不同版本的 PHP。
很可能您的启用 mysql 的版本有不同的处理程序,例如 application/x-httpd-php5 或其他东西

run phpinfo() in both files and see.
There will be 2 different versions of PHP.
Most likely your mysql-enabled version has a different handler, like application/x-httpd-php5 or something

白况 2024-09-22 10:20:29

这意味着 Apache Web 服务器上未安装或未正确加载 mod_mysql(MySQL 扩展)。

This means mod_mysql (MySQL extension) is not installed or was not loaded correctly on the Apache web server.

原谅我要高飞 2024-09-22 10:20:29

注释掉所有有问题的代码行,直到脚本运行(即使有警告和通知);在开始处放置 phpinfo(),运行脚本并检查它获取的 php.ini 内容。

您可能在某处有一个杂散的 php.ini ,其中 mysql 扩展被注释掉了...如果是这样,请编辑它以加载所需的 mysql 扩展。如果您发现加载了 mysqli 扩展,只需将代码中的每个 *mysql_** 函数更改为 *mysqli_** 即可。

Comment out all offending lines of code until the script runs (even if with warnings and notices); drop a phpinfo() at the start, run the script and check out what php.ini is it picking up.

You may have a stray php.ini somewhere with the mysql extension commented out... If so, edit it to load the required mysql extension. If you find out that the mysqli extension is loaded instead, just change every *mysql_** function in your code to *mysqli_** and you're done.

芸娘子的小脾气 2024-09-22 10:20:29

这是服务器问题。托管提供商承认这是他们的错误。

it's server issue. hosting provider admit that it's their mistake.

梦情居士 2024-09-22 10:20:29

尝试添加到 htaccess...

AddType application/x-httpd-php .html .htm

Try adding to htaccess...

AddType application/x-httpd-php .html .htm
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文