简体   繁体   中英

Why is mysqli_connect() an “undefined function” on my PHP server?

I'm using PHP Version 5.3.3 on a Linux server. When I try to use mysql_connect() or mysqli_connect() to reach the database, I get an error saying:

Fatal error: Call to undefined function mysql_connect()

or

Fatal error: Call to undefined function mysqli_connect()

You can see my testing page here: http://gorp.osg.ufl.edu/BOT3151/testing.php

You can see the phpinfo page here: http://gorp.osg.ufl.edu/phptest.php

The relevant configure commands are here:

'--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/lib64/mysql/mysql_config' '--with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config'

It also says that these .ini files are being parsed:

/etc/php.d/mysql.ini /etc/php.d/mysqli.ini

The php.ini file also includes these lines:

extension=mysql.so extension=mysqli.so

So what's going wrong here? Is mySQL not properly installed on the server? How can I fix this?

ADDENDUM: I should have explained that this is on a shared server that I don't administer. I just have access to my folder on the server through SFTP. But I do have a php.ini file and I have an extensions folder. So is this something I can fix myself or do I need help from a server administrator?

Try to install PHP MySQL by:

apt-get install php5-mysql

Then your MySQL is easily set with your PHP and Apache setting. If your MySQL is installed already you can uninstall it first and then try to install PHP MySQL by the code above in a terminal.

It is the easiest way to do it without needing any settings.

The "mysqli" extension is not loaded. You can NOT see the section in your phpinfo() file.

http://gorp.osg.ufl.edu/phptest.php

You should see something like this on that page: https://drive.google.com/open?id=0B7VdYIkRLxQWaDRLYVNLeU84am8

Just because you have uncommented the line extension=mysqli.so does not mean it will load. The file mysqli.so is possibly not in a folder where PHP is looking for it or does not exist at all.

Check "extension_dir" in your php.ini file. Then go and see if the file mysqli.so is actually there.

Have you restarted your web server?

鉴于您的PHP信息页面未列出显示MySQL配置的部分,因此可以推断可能未在您的服务器上安装MySQL。

I was facing similar issue. There was some problem with the default values in php.ini file. Please have a look at this answer if your problem wasn't solved with the answer given above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM