简体   繁体   中英

PHP can't connect to MYSQL after restart - Ubuntu 15.10

spent a few hours racking my brains, trying to fix this but I fear I'm not getting anywhere.

I set up localhost as a lamp environment yesterday on Ubuntu 15.10, everything was running fine and I made some good progress. Now I restart this morning and my project which I know I left working is now giving me

Fatal error: Call to undefined function mysqli_connect() in /var/www/html/includes/mysql.php on line 6

Now I know that there isn't a mistake in the code and mysql and apache is definately running.

elliot@elliotsLaptop:~$ mysqladmin -u root -p status
Enter password: 
Uptime: 3588  Threads: 1  Questions: 19  Slow queries: 0  Opens: 69  
Flush tables: 1  Open tables: 62  Queries per second avg: 0.005.

elliot@elliotsLaptop:~$ service apache2 status
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2)
Active: active (running) since Wed 2016-04-20 09:02:18 BST; 1h 1min ago

Also I made no changed to the PHP.ini file when I originally set it up, but now both mysqli_connect and mysql_connect are both undefined functions and mysqli is an undefined class.

Fatal error: Class 'mysqli' not found in /var/www/html/includes/mysql.php on line 6

So it seems to be some kind of setting has change inside my php setup but I can't for the life of me figure out what it is.

This is PHP Version 5.6.11. Anyone have any experience with this kind of problem? I'm close to reinstalling PHP but I'd rather understand what is going on or what I may be doing wrong.

Any advice would be severly appreciated.

Try Below Command:

Latest phpMyAdmin versions require mysqli extension and will no longer work with mysql.

sudo apt-get install php5-mysql

Please add below line php.ini

extension=mysqli.so

Please restart server hope this works

For some reason, taking the mysql connection out of an include and putting it directly onto the page that was using it seems to have fixed the problem. I have no real idea why this would be the case but everything now seems to be working as expected.

Thanks a lot to everyone who tried to help me with this.

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