如果文件扩展名从 html 重写为 php,PHP 函数 mysql_connect() 不起作用
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在两个文件中运行 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
这意味着 Apache Web 服务器上未安装或未正确加载 mod_mysql(MySQL 扩展)。
This means mod_mysql (MySQL extension) is not installed or was not loaded correctly on the Apache web server.
注释掉所有有问题的代码行,直到脚本运行(即使有警告和通知);在开始处放置
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 whatphp.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.这是服务器问题。托管提供商承认这是他们的错误。
it's server issue. hosting provider admit that it's their mistake.
尝试添加到 htaccess...
Try adding to htaccess...