Jump to content

Call to undefined function mysqli_connect()


waddledoo

Recommended Posts

EDIT: I just found http://www.phpfreaks.com/forums/index.php/topic,95378.0.html which is an FAQ on this very problem and am reading it now. I have posted this edit in case anyone views this post as I read the FAQ, and will either delete this post (if the FAQ solves this) or leave it if I require more help.

 

MySQL Version: MySQL Server 5.5

 

This isn't as much a SQL code problem as it is an accessing MySQL itself. If this should be moved elsewhere, please tell me.

 

I am attempting to connect to MySQL on my own computer through localhost, using the following code (I realize the guidelines state "in a CODE block, and without any PHP variables" but I don't know where else to put this):

 

<?php
$link = mysqli_connect('localhost', '[i]username[/i]', '[i]password[/i]');
if (!$link)
{
	$output = 'Unable to connect to the database server.';
	include 'output.html.php';
	exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
	$output = 'Unable to set database connection encoding.';
	include 'output.html.php';
	exit();
}
?>

 

However, I get the following error:

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test1.php on line 2

 

I have been searching online for the solution to this for hours now, with no success.

I have found many similar problems but no fixes I can find are changing anything (which frustrates me as either I am doing something terribly wrong or have a very bad issue).

 

Yes, I have set up the php.ini file correctly (as far as I can tell)

 

My PHP file is located at "C:\PHP", and below is my code for the extension folder:

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "C:\PHP\ext\"
; On windows:
extension_dir = "C:\PHP\ext"

 

I have un-commented the "php_mysqli.dll", as shown in context with code here:

;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_exif.dll      ; Must be after mbstring as it depends on it
;extension=php_mysql.dll
extension=php_mysqli.dll    ; <-- notice the lack of semicolon... I wish it had been that easy 
;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
<etc etc...>

 

As for the file "libmysql.dll", it does not exist in my PHP folder anywhere, but is located in the "lib" folder of "My SQL Server 5.5".

Attempts to place this in either the PHP folder or in the general system's path (System32 folder) have given me no success.

 

I have also been restarting the server (Apache 2.2) after every change to the php.ini file, or to moving files.

 

If anyone can help with this, or at least redirect me to where I can get help, it would be greatly appreciated.

 

I really hope that I'm just missing something obvious, and feel free to smack me upside the head for it if you find it :)

 

Thankyou

Link to comment
Share on other sites

Based on the information in your post, you need to check that the php.ini that you are changing is the one that php is using.

 

Make a .php script file with the following in it, and browse to this file -

 

<?php
phpinfo();
?>

 

The value for - Loaded Configuration File is the php.ini that php is using.

 

Also, since you are using Windows, have you changed the Windows setting that 'hides extensions for known file types' as this could be hiding the actual extension of the php.ini that you have been editing (it may not be just php.ini).

Link to comment
Share on other sites

I have made such file to view such information, and it has always displayed this (I included the item "Configuration File (php.ini) Path" as it looks like it may have something to do with the problem):

 

Configuration File (php.ini) Path C:\Windows

Loaded Configuration File C:\PHP\php.ini

 

And yes, my settings currently do not hide any extensions.

 

The loaded config file directs me to the file I have been editing, but looking at this now I don't know what (if anything) the one above it means.

Link to comment
Share on other sites

This is on my computer (localhost) and not a web server.

 

...I am attempting to connect to MySQL on my own computer through localhost...

 

I haven't tried using a webserver yet. I don't want to commit the money until I am confident I can create what I want, or until there is nothing more I can test without one.

Link to comment
Share on other sites

not a web server

 

Apache is a web server. In fact, I believe, it is the current most popular web server in use around the world. The URLs you have been entering in your browser - http://localhost/somefile.php cause HTTP requests to be made to the Apache web server you have installed on your computer.

 

I have a follow up question about your actual problem. How did you obtain and install php, because if you used the .msi installer package, you must use the Windows control panel add/remove menu to add php extensions.

Link to comment
Share on other sites

As for the web server, I thought he meant web host (other than my own computer).

 

As for how I installed PHP, I used the information found on http://www.sitepoint.com/php-amp-mysql-1-installation/ and downloaded the "VC9 x86 Thread Safe" Zip File from http://windows.php.net/download/

 

I also know that PHP installed, as opening Apache Service Monitor displays Apache/2.2.21 (Win32) PHP/5.3.8

 

I did not use an installer/msi file

 

EDIT: Btw thanks for your help so far, even if my problem isn't solved yet. It reduces frustration when there is hope XD

Link to comment
Share on other sites

Wow. I can't believe it was so simple, but it seems I just fixed the problem.

 

My code for actually locating the server was as follows:

; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues.  The alternate is to use the
; cgi.force_redirect configuration below
; http://php.net/doc-root
doc_root = C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs

 

But then I noticed a lack of quotes, so I changed it to:

doc_root = "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs"

 

And I receive no errors. Also under phpinfo() it now displays mysql and mysqli sections that were not there before.

I placed an echo into my code to display if everything worked, and I got the echo display.

 

I am so glad it was just some stupid mistake on my part... I didn't want to deal with a complicated solution XD

 

This post can be marked as solved (unless I'm supposed to do that, in which case I haven't a clue how)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.