Jump to content

mysql_connect vs. mysqli_connect


The Praetorian

Recommended Posts

Okay. According to my domain provider, their current version of mysql supports mysqli_connect. And yet... when I try to use it.. I still get this error.Fatal error: Call to undefined function: mysqli_connect() in /home/author/public_html/connect_string.txt on line 3I checked the code ten times and I can't see anything wrong with it. It even works fine on my localhost. I'm stumped. For security I have an external file with the host, username, password and db set as variables.

<?phpinclude '../includes/keys.txt';$cxn = mysqli_connect ("$host","$user_name","$password","$db") or die ("I cannot connect to the database because: " . mysql_error());?>

Link to comment
Share on other sites

First, let me point out that that is absolutely not secure as-is. To prove it, open a browser (actually, you've probably already done that..) and navigate directly to the keys.txt file. If you can see it in the browser, then, well, everyone else can too. The simple solution is to rename it to .php instead of .txt. If you do that and load it in the browser, then you will see a blank page.Anyway, it's not MySQL only that needs to support the improved extension, PHP also needs it. Open phpinfo in a browser and you can see if the mysqli extension is loaded:

<?php phpinfo(); ?>

Scroll down and look for a mysqli extension. If you don't see one, then PHP does not have it loaded. You may need to contact your host if that is the case and ask them to enable the mysqli extension inside php.ini.

Link to comment
Share on other sites

That's the thing. They keep telling me it is enabled. And yet.. it doesn't work. That's why I question if it's my code.On a side note, thanks for the concern, but the keys.txt file isn't stored in a live directory. It's stored one directory up (thus the ../ before the /include/.) So no one would be able to look at it anyway.

Link to comment
Share on other sites

Well there's nothing wrong with the code, you can prove that by the fact that it works on your machine. So the difference between you running it on your machine or on theirs isn't the code, the difference is their machine. So you would probably want to contact them and ask them why the function is not enabled. Either the extension is not loaded, they have the function restricted, or they aren't running PHP5.

Link to comment
Share on other sites

Oi. My server is giving me the run around. This is what they sent me. Now.. I may not understand all of this... but it seems to be on the first read-through that in the same email they say that they have it enabled.. but it won't work....?

We have MySQLi enabled in our server.We have uploaded a phpinfo page in to your public_html.Kindly click the link below to access the same.http://tsrealms.com/test.php=========================================================================Details of phpinfo page './configure' '--enable-pic' '--with-apxs=/usr/local/apache/bin/apxs' '--with-libdir=lib64' '--prefix=/usr/local' '--with-xml' '--enable-bcmath' '--enable-calendar' '--with-curl' '--with-dom' '--with-dom-xslt' '--with-dom-exslt' '--enable-exif' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-gettext' '--with-imap=/usr/local/imap-2004g' '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-mcrypt' '--with-mhash' '--enable-magic-quotes' '--with-mysqli' '--with-mysql=/usr' '--with-openssl' '--enable-discard-path' '--with-pear' '--with-pspell' '--enable-sockets' '--enable-track-vars' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--enable-wddx' '--with-zlib'==========================================================================MySQLi is not able to connect to host using mysqli_connect() since remote MySQL connection is not allowed.

Link to comment
Share on other sites

  • 3 years later...

Why are you calling your PHP files ".txt"? It should be ".php"!Also, their message tells you what's the problem:

MySQLi is not able to connect to host using mysqli_connect() since remote MySQL connection is not allowed.
What's the value of $host? Is it by any chance different than "localhost" or "127.0.0.1"? They're telling you remote connections are not allowed with them, so if you're trying to connect to another server (e.g. your computer), you'll fail.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...