php script, run on ubuntu system, it costs php7, when you try to start the script with php script.php it gives an error

PHP 7 Fatal error: Call to undefined function mysqli_connect () on line 11

line 11 here:

$connect_to_db = mysqli_connect($domain, $username, $password, $db) 

what could be the problem? If you run the same script through the web, it works

  • one
    In php.ini, uncomment the line extension=mysqli.so (approximate view) and restart php. - Visman
  • Use PDO already ... - DaemonHK
  • @Visman in php.ini which is in /etc/php/7.0/cli? - Drop

2 answers 2

need to install mysql extension for php7.

 sudo apt-get install php7.0-mysqlnd sudo phpenmod mysqlnd sudo service apache2 restart 
  • worth the latest version - Drop
  • @Drop print the result of phpinfo (); I need the PHP Version line at the top and if there are any mysqli matches. - tcpack4
  • @ tcpack4, PHP Version 7.0.18-0ubuntu0.17.04.1 prntscr.com/g318oo - Drop
  • @Drop try the updated command above. - tcpack4
  • @ tcpack4, writes Note like this, selecting 'php7.0-mysql' instead of 'php7.0-mysqlnd' php7.0-mysql is the newest version (7.0.18-0ubuntu0.17.04.1). 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded. - Drop

Most likely you do not have mysqli PHP extension installed. You can install this command:

 sudo apt-get install php-mysql 
  • worth the latest version - Drop