{"id":3311,"date":"2022-04-21T19:37:59","date_gmt":"2022-04-21T18:37:59","guid":{"rendered":"https:\/\/www.dpscomputing.com\/blog\/?p=3311"},"modified":"2022-04-21T19:38:01","modified_gmt":"2022-04-21T18:38:01","slug":"fatal-error-call-to-undefined-function-mysqli_connect","status":"publish","type":"post","link":"https:\/\/www.dpscomputing.com\/blog\/2022\/04\/21\/fatal-error-call-to-undefined-function-mysqli_connect\/","title":{"rendered":"Fatal error: Call to undefined function mysqli_connect()"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignright size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3315\" data-permalink=\"https:\/\/www.dpscomputing.com\/blog\/2022\/04\/21\/fatal-error-call-to-undefined-function-mysqli_connect\/image-21-2\/\" data-orig-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21.png\" data-orig-size=\"623,366\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-21\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21-300x176.png\" data-large-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21.png\" tabindex=\"0\" role=\"button\" src=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21.png\" alt=\"\" class=\"wp-image-3315\" width=\"312\" height=\"183\" srcset=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21.png 623w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21-300x176.png 300w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-21-150x88.png 150w\" sizes=\"auto, (max-width: 312px) 100vw, 312px\" \/><\/figure><\/div>\n\n\n\n<p>So you&#8217;ve come across this error, you&#8217;ve changed every line of code 3000 times and still it won&#8217;t work.  What gives?  <\/p>\n\n\n\n<p>This error is stubbornly staring back at you:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Fatal error: Call to undefined function mysqli_connect()<\/code><\/pre>\n\n\n\n<p>The reason why no matter how much you change and tweak nothing seems to work is that your code isn&#8217;t wrong.  Or, more specifically, your code may be wrong &#8211; but it isn&#8217;t causing this error!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The cause<\/h2>\n\n\n\n<p>Essentially this error is being thrown by PHP as it doesn&#8217;t have the first clue what mysqli_connect() is.  In other words, it doesn&#8217;t exist.  <\/p>\n\n\n\n<p>BUT I hear you call out &#8211; everybody is using it!  They are &#8211; and the reason they can use it but your current setup isn&#8217;t allowing it is because you don&#8217;t have the appropriate MySQLi adapters installed along correctly on your server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to check<\/h2>\n\n\n\n<p>A simple way to check this is running the phpinfo() function.  Comment everything out (or create a new test file) and place the following line of code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>phpinfo();<\/code><\/pre>\n\n\n\n<p>Running this page should now present you with a raft of information about your PHP setup &#8211; this will work on both a web server and a local development server.  <\/p>\n\n\n\n<p>You&#8217;ll get a page of output looking similar to the below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"201\" data-attachment-id=\"3313\" data-permalink=\"https:\/\/www.dpscomputing.com\/blog\/2022\/04\/21\/fatal-error-call-to-undefined-function-mysqli_connect\/image-19-2\/\" data-orig-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19.png\" data-orig-size=\"1878,369\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-19\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-300x59.png\" data-large-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-1024x201.png\" tabindex=\"0\" role=\"button\" src=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-1024x201.png\" alt=\"\" class=\"wp-image-3313\" srcset=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-1024x201.png 1024w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-300x59.png 300w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-150x29.png 150w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-768x151.png 768w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19-1536x302.png 1536w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-19.png 1878w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>It&#8217;s easy to get overwhelmed with all the data, so we&#8217;re looking for something very specific here.  Scroll down or search (CTRL+F or CMD+F on Mac) for &#8216;mysqli&#8217;.  It should be on it&#8217;s own section and, if the plugin is installed correctly you should notice that it says below the title &#8216;Mysqli Support &#8211; enabled&#8217;:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"582\" height=\"275\" data-attachment-id=\"3314\" data-permalink=\"https:\/\/www.dpscomputing.com\/blog\/2022\/04\/21\/fatal-error-call-to-undefined-function-mysqli_connect\/image-20-2\/\" data-orig-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20.png\" data-orig-size=\"582,275\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-20\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20-300x142.png\" data-large-file=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20.png\" tabindex=\"0\" role=\"button\" src=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20.png\" alt=\"\" class=\"wp-image-3314\" srcset=\"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20.png 582w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20-300x142.png 300w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20-150x71.png 150w, https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20-520x245.png 520w\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" \/><\/figure><\/div>\n\n\n\n<p>You could also us this piece of code to confirm what you already know if you don&#8217;t want to scroll through the phpinfo() list:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(function_exists('mysqli_connect'));<\/code><\/pre>\n\n\n\n<p>This will return TRUE if the function exists &#8211; and therefore the plugin is active and working &#8211; or false if it doesn&#8217;t.  However, given the error message above says that mysqli_connect() is undefined, you can bet a fairly safe bet you will get false returned here.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to install MySQLi support for PHP<\/h2>\n\n\n\n<p>On a Linux based server, in the terminal you can enter the following command to retrieve and install the php-mysql package to enable support for the mysqli commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install php-mysql<\/code><\/pre>\n\n\n\n<p>You may need to reboot your server after installation is completed.  <\/p>\n\n\n\n<p>Using EasyApache (for example, through Web Host Manager &#8211; WHM) makes it even easier and you can avoid the terminal\/command line if you&#8217;re not a fan of it!<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Login to WHM as the main (usually &#8216;root&#8217;) user.  <\/li><li>Select &#8216;EasyApache&#8217; from the menu on the right hand side.  <\/li><li>Select your &#8216;Previously Saved Config&#8217; &#8211; this will ensure you keep all your existing profile settings from the last time you complied\/recompiled Apache.  <\/li><li>Click the &#8216;Start&#8217; button to start customising the profile.  <\/li><li>You can keep your Apache and PHP versions the same by clicking the &#8216;Next&#8217; button.  <\/li><li>For the additional options, you&#8217;ll need to select the MySQL Improved extension from the &#8216;Exhaustive Options List&#8217;.  <\/li><li>Save and build.  Once finished Apache should automatically restart and if you re-run your code above it should now work as MySQLi support has been added.  <\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Still not working?<\/h2>\n\n\n\n<p>The final step, if it isn&#8217;t automatically done (which it usually is) is to ensure that the php.ini file (your PHP configuration settings file) is updated to use the new MySQLi plugin.  <\/p>\n\n\n\n<p>Open the PHP.ini file and search for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>extension=php_mysqli.so<\/code><\/pre>\n\n\n\n<p>This line may be commended out (using a semicolon &#8211; \ud83d\ude09 at the beginning of the line.  If you see a semi-colon, remove it, save your PHP.ini file.  <\/p>\n\n\n\n<p>Finally, restart your Apache server (either through your control panel or, if running locally, quit the server and restart the application) and hey presto, your code should run like a dream now!<\/p>\n\n\n\n<p>Hope that helps &#8211; let us know any comments below!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you&#8217;ve come across this error, you&#8217;ve changed every line of code 3000 times and still it won&#8217;t work. What gives? This error is stubbornly staring back at you: The reason why no matter&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":3314,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Fatal error: Call to undefined function mysqli_connect()\n\nYou've changed your code a million times BUT it's not fixing because you're looking in the wrong place!\n\nCheck out the simple no-code solution to your woes!\n\n#mysqli #mysqlierror #phpmysqli","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[2139],"tags":[2939,2925,2453,2941,2860,2758,2940,2456,2457],"class_list":["post-3311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development-issues","tag-fatal-error-call-to-undefined-function-mysqli_connect","tag-mysql","tag-mysql-error","tag-mysql-fatal-error","tag-mysqli","tag-mysqli-error","tag-mysqli-fatal-error","tag-mysqli_connect-error","tag-mysqli_connect"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.dpscomputing.com\/blog\/wp-content\/uploads\/2022\/04\/image-20.png","jetpack_shortlink":"https:\/\/wp.me\/p3nsfA-Rp","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/posts\/3311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/comments?post=3311"}],"version-history":[{"count":1,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/posts\/3311\/revisions"}],"predecessor-version":[{"id":3316,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/posts\/3311\/revisions\/3316"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/media\/3314"}],"wp:attachment":[{"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/media?parent=3311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/categories?post=3311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dpscomputing.com\/blog\/wp-json\/wp\/v2\/tags?post=3311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}