Page 1 of 2

PHP Fatal error: Class 'MySQLi' not found

PostPosted: 21. December 2016 11:04
by deepshikha
I am using Xampp (xampp-linux-x64-7.0.13-0) on linux. I am not able to connect to mysql database through php code.I got error PHP Fatal error: Class 'MySQLi' not found in /opt/lampp/htdocs/test5/connection.php on line 3. here is the code:
<?php // sqltest.php
require_once 'login5.php';
$conn = new \MySQLi($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);

if (isset($_POST['delete']) && isset($_POST['isbn']))
{
$isbn = get_post($conn, 'isbn');
$query = "DELETE FROM classics WHERE isbn='$isbn'";
$result = $conn->query($query);
if (!$result) echo "DELETE failed: $query<br>" .
$conn->error . "<br><br>";
}

if (isset($_POST['author']) &&
isset($_POST['title']) &&
isset($_POST['category']) &&
isset($_POST['year']) &&
isset($_POST['isbn']))
{
$author = get_post($conn, 'author');
$title = get_post($conn, 'title');
$category = get_post($conn, 'category');
$year = get_post($conn, 'year');
$isbn = get_post($conn, 'isbn');
$query = "INSERT INTO classics VALUES" .
"('$author', '$title', '$category', '$year', '$isbn')";
$result = $conn->query($query);

if (!$result) echo "INSERT failed: $query<br>" .
$conn->error . "<br><br>";
}

echo <<<_END
<form action="sqltest.php" method="post"><pre>
Author <input type="text" name="author">
Title <input type="text" name="title">
Category <input type="text" name="category">
Year <input type="text" name="year">
ISBN <input type="text" name="isbn">
<input type="submit" value="ADD RECORD">
</pre></form>
_END;

$query = "SELECT * FROM classics";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);

$rows = $result->num_rows;

for ($j = 0 ; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);

echo <<<_END
<pre>
Author $row[0]
Title $row[1]
Category $row[2]
Year $row[3]
ISBN $row[4]
</pre>
<form action="sqltest.php" method="post">
<input type="hidden" name="delete" value="yes">
<input type="hidden" name="isbn" value="$row[4]">
<input type="submit" value="DELETE RECORD"></form>
_END;
}

$result->close();
$conn->close();

function get_post($conn, $var)
{
return $conn->real_escape_string($_POST[$var]);
}
?>

I struck badly on this step I have removed semicolon in front of extension=php_mysqli.so in php.ini but no use. Please help me if somebody have solution.

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 21. December 2016 13:02
by Nobbie
>I struck badly on this step I have removed semicolon in front of extension=php_mysqli.so in php.ini but no use. Please help me if somebody have solution.

There is NO(!) such line in php.ini (/opt/lampp/etc/php.ini) and it would also be wrong to remove the semicolon, as MySQLi is statically linked into the PHP module. Which php.ini do you mean (as there is no php_mysqli.so in Xampp) and are you sure you are running Xampp?

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 21. December 2016 13:06
by deepshikha
yes i am running Xampp, you are right there is no file with name php_mysqli.so in xampp but in php.in you can find this line extension=php_mysqli.so

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 21. December 2016 13:07
by deepshikha
and I am talking about php.ini (/opt/lampp/etc/php.ini) only,
do you have any idea why I am getting this error?PHP Fatal error: Class 'MySQLi' not found

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 21. December 2016 13:26
by Nobbie
deepshikha wrote:but in php.in you can find this line extension=php_mysqli.so


No!

There is NO line which contains php_mysqli.so in php.ini (there is only one line " extension=php_mysqli.dll", but as you can see, it does have the wrong extension *.dll). If your php.ini contains an entry like "extension=php_mysqli.so", you must have overwritten php.ini by another version. I just installed a fresh xampp-linux-x64-7.0.13-0-installer.run

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 22. December 2016 06:55
by deepshikha
I uninstall xampp and freshly install xampp-linux-x64-7.0.13-0-installer.run and here is the part of php.ini file, and see here is .so file mention in this file
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
;
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_exif.dll
;extension=php_fileinfo.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11g Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_phar.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

;extension="zip.so"

;extension="sqlite.so"

;extension="radius.so"

;extension="pgsql.so"

; disabled in XAMPP 1.7.2 because incompatible with PHP 5.3.0
;extension="dbx.so"

;extension="ming.so"

;extension="ncurses.so"

;extension="dio.so"

;extension="interbase.so"

; disabled in XAMPP 1.7.2 because incompatible with PHP 5.3.0
;extension="eaccelerator.so"
;eaccelerator.shm_size="16"
;eaccelerator.cache_dir="/opt/lampp/temp/eaccelerator"
;eaccelerator.enable="1"
;eaccelerator.optimizer="1"
;eaccelerator.check_mtime="1"
;eaccelerator.debug="0"
;eaccelerator.filter=""
;eaccelerator.shm_max="0"
;eaccelerator.shm_ttl="0"
;eaccelerator.shm_prune_period="0"
;eaccelerator.shm_only="0"
;eaccelerator.compress="1"
;eaccelerator.compress_level="9"

;oci8mark


;zend_extension=opcache.so

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 22. December 2016 11:59
by Nobbie
deepshikha wrote:I uninstall xampp and freshly install xampp-linux-x64-7.0.13-0-installer.run and here is the part of php.ini file, and see here is .so file mention in this file


Still no.

You explicitely said this:

"I have removed semicolon in front of extension=php_mysqli.so in php.ini but no use"

Please show me the line with ";extension=php_mysqli.so" where you removed the semicolon!? That is exactly what you said and i still cannot see such a line. Where is it?

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 23. December 2016 11:42
by deepshikha
There was no error in my php.ini file. the whole culprit was my IDE (eclips). the path of my php executable was not accurate that is why "PHP Fatal error: Class 'MySQLi' not found" was there. when I change my php executables' path to /opt/lampp/bin/php, error was removed.
thanks to all for response and support.

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 23. December 2016 21:07
by Nobbie
deepshikha wrote:the whole culprit was my IDE (eclips)


Horrible....

Instead of telling us about your IDE, you lied about php.ini and removing a semicolon before "extension=php_mysqli.so", what you never did. Hopefully you are feeling as bad as possible about this mega annoying "question". It is a pain in fact.

deepshikha wrote:thanks to all for response and support.


Hopefully the very last one. I wont ever answer to any of your lies.

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 23. December 2016 21:34
by Altrea
Sorry, but didn't you think that it is a very important information that your error message was displayed inside your IDE instead directly from the PHP interpreter?
Without this information it is impossible to guess the reason.

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 24. December 2016 07:54
by deepshikha
yes you are right . error was on my part, I should have draft my question more carefully, but I was so panic that not able to figure out where is the problem. I will post next time more carefully.

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 24. December 2016 11:44
by Nobbie
deepshikha wrote: I should have draft my question more carefully, but I was so panic that not able to figure out where is the problem. I will post next time more carefully.


It is not only a question of being carefully, i doubted and asked you three times about php.ini, but you constantly insisted on your lie that you removed a semicolon in front of a line, which does not exist. That is, what i cannot understand. Why didnt you simply agree??

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 25. December 2016 07:01
by deepshikha
colored and bold line...If you can see.
why should I speak lie to you? PHP is new for me and got confused. thats all.
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
;
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_exif.dll
;extension=php_fileinfo.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11g Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_phar.dll
;extension=php_pspell.dll

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 25. December 2016 12:23
by Nobbie
deepshikha wrote:colored and bold line...If you can see.
; extension=msql.so


This line is NOT:

; extension=mysqli.so

Do you want to tell me, that you really cannot see the difference between "msql" and "mysqli"?? I dont believe that. In your posting you always said "mysqli.so", never ever "msql.so". This is a MEGAHUGE difference.

Re: PHP Fatal error: Class 'MySQLi' not found

PostPosted: 25. December 2016 17:16
by JJ_Tagy
Semicolons make a big difference too.