Jump to content
m4u_hoahoctro

Call undefined function mysqli_connect()

Recommended Posts

I am a newbie, and I have just learned some knowledges about php

Today I tried using some command to work with database MySQL

In editor of phpdesigner, I typed this code:

 

<?php
phpinfo(); 
 
// Create connection
    $db = mysqli_connect("localhost", "booksdb", "TABLEname") or die(mysqli_connect_error());
 
 
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
 
?>
 
but when Ctrl + F9 to compile, It show error: Fatal error: Call undefined function mysqli_connect()
 
I saw some questions same me asked on stackoverlow, some ones said the reason is extension mysql has't been enabled yet. But I don't know how to to that ? ( I also setuped Xampp and Vertrigo )
 
So I need a suggestion from other members
 
Thanks for reading

Share this post


Link to post
Share on other sites

What operating system and server packages are you using now?

 

phpinfo(); is to see about server configuration, do you see a mysqli section? if so it's installed.

 

Look at Loaded Configuration File and visit that php.ini file location, ensure is no ; in front of extension=php_mysqli.dll

If you made a change and saved the file then restart apache service.

 

The correct way to connect is host,user,password,database

$db = mysqli_connect("localhost","user_name","user_password","database_name") or die("Error " . mysqli_error($db)); 

Share this post


Link to post
Share on other sites

I found 2 lines

extension=php_mysql.dll
extension=php_mysqli.dll
 
I remove ";" and restart vertrigo
but the problem is still exsiting
 
:confused:

Share this post


Link to post
Share on other sites

vertrigo is not apache

sorry because I haven't had many knowledges about web

but I modified above lines as you said, so if not enough, what shoud I do next ?

Share this post


Link to post
Share on other sites

Do you have any problem with some other php function or only with this one? Could you run this script and give us the output (should be mysqli_connect function is not available).  Try also the old mysql_connect instead mysqli_connect.

<?php

if (function_exists('mysqli_connect')) {
    echo "mysqli_connect function is available.<br />\n";
} else {
    echo "mysqli_connect function is not available.<br />\n";
}
Edited by jazzman1

Share this post


Link to post
Share on other sites

 

Do you have any problem with some other php function or only with this one? Could you run this script and give us the output (should be mysqli_connect function is not available).  Try also the old mysql_connect instead mysqli_connect.

<?php

if (function_exists('mysqli_connect')) {
    echo "mysqli_connect function is available.<br />\n";
} else {
    echo "mysqli_connect function is not available.<br />\n";
}

I tested on host of 000webhost. and result is "mysqli_connect function is available."

 

so the aim I want is able to remove error: Fatal call to undefined function mysql  :sweat: when compile in phpdesigner software

thanks much for helping

 

Share this post


Link to post
Share on other sites

Yeap, you have a problem with your local setup. What happens if you're using mysl_connect instead mysqli_connect function?

Share this post


Link to post
Share on other sites

Yeap, you have a problem with your local setup. What happens if you're using mysl_connect instead mysqli_connect function?

 

I tried using both code with above 2 functions, add compiler still announces: Fatal call to undefined..........

In this case, does my computer has some problem ?

ok I will create new database on 000webhost and try writting a connected app php

thanks

Share this post


Link to post
Share on other sites

Try to run echo "Hello World"; onto your local machine and tell us what's going on. I am not sure how proper is you local setup config. 

Share this post


Link to post
Share on other sites

Re-run

phpinfo();

and see if the MySQLi section has appeared and check the Loaded Configuration File setting to make sure you edited the correct php.ini file

Share this post


Link to post
Share on other sites

Yes, that confirms that MySQLi is installed and the functions should be available to you

Share this post


Link to post
Share on other sites

the phpdesigner ide you are using is invoking php directly, not through the web server.

 

you either need to invoke your files using a browser, through the web server, or you need to configure phpdesigner to use the same php.ini that the web based php is using. see the following from the phpdesigner documentation -

 

If you are working with PHP extensions such as MySQL please specify where to find the PHP configuration file (php.ini).

 

On the Tools menu, point to Preferences

Select Debugger

In the field 'Configuration File' check and type in the path for the configuration file (.ini), or click the Browse button to locate the PHP interpreter

Share this post


Link to post
Share on other sites

the phpdesigner ide you are using is invoking php directly, not through the web server.

 

you either need to invoke your files using a browser, through the web server, or you need to configure phpdesigner to use the same php.ini that the web based php is using. see the following from the phpdesigner documentation -

 

 

I did as you told, but the error still appears  :sweat:

Edited by m4u_hoahoctro

Share this post


Link to post
Share on other sites

at this point i don't think we know what exactly you have or what's being ran. you stated you installed xampp and Vertrigo. afaik, those both would have attempted to install Apache/Mysql/Php and either would have produced installation errors or perhaps installed two different apache/mysql servers using different port numbers.

 

when you are running the phpinfo(); statement to find the php.ini and the mysqli information, how exactly are you invoking the .php script containing the phpinfo() statement? through phpdesigner or are you using your browser with a url something like - http://localhost/your_php_file.php ?

Share this post


Link to post
Share on other sites

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.