i have installed Linux Mint 18.1, then LAMP server using the command
sudo apt-get install lamp-server^ , for testing i tried to create a script connecting to MYSQL database, just like the following.
<?php
$h = "localhost";
$u = "root";
$p = "password";
$conn = mysql_connect($h,$u,$p);
echo "test";
?>
when i remove the line $conn = mysql_connect($h,$u,$p);
the script works fine, otherwise it isn't running,
php5.6-mysql is already installed , and i also tried to connect using
mysqli_connect() instead of mysql_connect()
i don't know what's wrong ?!
Paste this at the top of your file:
error_reporting(E_ALL);
ini_set('display_errors', 1);
It will help you to see the exact error.
Alternatively, you can try:
$conn = mysql_connect($h,$u,$p) or die('Connection Error');
If connection is not getting established then it will show Connection Error
Here is my problem: Fatal error: Call to undefined function mssql_connect().
I installed 2 drivers for this, as explained in other posts.
php_pdo_sqlsrv_56_nts.dll
php_sqlsrv_56_nts.dll
<?php
$myServer = ".";
$myUser = "LoginDisciples";
$myPass = "********";
$myDB = "Disciples";
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
?>
The login information is all correct.
Please help!
You should use PDO
If there is a missing driver - here is an Ubuntu example how to install:
1) download driver sudo apt-get install php5-xxx
2) activate driver sudo php5enmod xxx
3) restart apache sudo service apache2 restart
I just recently upgraded my server's PHP version to 5.4.22, and now every script that uses PDO does not work.
An example of my PHP script which won't work:
<?php
$dsn = 'mysql:dbname=testDB;host=127.0.0.1';
$user = '[hidden]';
$password = '[hidden]';
try {
$pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
?>
When i run the script i get: Fatal error: Class 'PDO' not found, i get this same error for every script that creates a connection.
I ran a check on puTTY to check PDO was even there and it found this:
root#cpanel [~]# php -m | grep -i pdo
PDO
pdo_mysql
pdo_sqlite
My php.ini has
extension=pdo.so
extension=pdo_sqlite.so
; sqlite was removed by EasyApache v3.22.24 on Sat Dec 14 23:24:10 2013 (PHP v5.4.x incompatibility)
; extension=sqlite.so
extension=pdo_mysql.so
phpinfo(); in PHP file claims im on PHP Version 5.3.10
How ever in my terminal # php -v says PHP 5.4.22
So this had really confused me why i'm getting two versions.
Your question shows that you are checking the PHP version via the command line. But PHP via a web browser is going to use a module loaded into Apache which is a completely different thing. So check the output of phpinfo(); in a PHP script loaded via the web browser. Is PDO installed or shows as installed via that?
Wherever your Apache config files are look for the directory mods-available and the file php5.load. Under Ubuntu 12.04 it would be in this path:
/etc/apache2/mods-available/php5.load
And the contents should be:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Does the path in that file match where the newly compiled libphp5.so is installed?
Also, that LoadModule php5_module line could be a part of your main Apache configuration. Look around to find where that is set. And then just set the path of the new module to me wherever it’s actually installed.
This question already has answers here:
Fatal error: Uncaught Error: Call to undefined function mysql_connect()
(9 answers)
Closed 3 months ago.
I have set up PHP, MySQL, and Apache. localhost() for PHP and it is working well. But after I downloaded MySQL, it reports:
Fatal error: Call to undefined function mysql_connect()
How can I fix this?
You upgraded to PHP 7, and now mysql_connect is deprecated. Check yours with:
php -version
Change it to mysqli_connect as in:
$host = "127.0.0.1";
$username = "root";
$pass = "foobar";
$con = mysqli_connect($host, $username, $pass, "your_database");
If you're upgrading legacy PHP, now you're faced with the task of upgrading all your mysql_* functions with mysqli_* functions.
If you get this error after upgrading to PHP 7.0, then you are using deprecated libraries.
mysql_connect — Open a connection to a MySQL Server Warning This
extension was deprecated in PHP 5.5.0, and it was removed in PHP
7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
More here: http://php.net/manual/en/function.mysql-connect.php
Open your terminal and run bellow command.
sudo apt-get install mysql-server
If you are running PHP you will also need to install the php module for mysql 5:
sudo apt-get install php5-mysql
Verify that your installation of PHP has been compiled with mysql support. Create a test web page containing <?php phpinfo(); exit(); ?> and load it in your browser. Search the page for MySQL. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in
PHP.INI
Check if you forgot to enable the options below(loads the modules for mysql among others):
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"
Use.
<?php $con = mysqli_connect('localhost', 'username', 'password', 'database'); ?>
In PHP 7.
You probably have PHP 7 in XAMPP. You now have two option: MySQLi and PDO.
For CPanel users, if you see this error and you already have PHP 5.x selected for the site, there might be a CPanel update that disabled mysql and mysqli PHP extensions.
To check and enable the extensions:
Go to Select PHP Version in CPanel
Make sure you have PHP 5.x selected
Make sure mysql and mysqli PHP extensions are checked
This error is coming only for your PHP version v7.0.
you can avoid these using PHP v5.0
else
use it
mysqli_connect("localhost","root","")
i made only mysqli from mysql
A solution could be to use adapter functions like these to start using mysqli instead of mysql over your entire application:
if (!function_exists('mysql_connect')) {
function mysql_connect($host = '', $user = '', $password = '', $database = '', $port = 0, $socket = '') {
return mysqli_connect($host, $user, $password, $database, $port, $socket);
}
}
if (!function_exists('mysql_select_db')) {
function mysql_select_db($link, $dbname) {
mysqli_select_db($link, $dbname);
}
}
I had this same problem on RHEL6. It turns out that the mysql.ini file in /etc/php.d only had a module name but needed a full path name. On my RHEL6 system the entry that works is:
; Enable mysql extension module
extension=/usr/lib64/php/modules/mysql.so
After modifying the file, I restarted apache and everything worked.
My solution is here (I needed just to remove the last slash (NB: backward slashes) from PHPIniDir 'c:\PHP\'): Fatal error: Call to undefined function mysql_connect() cannot solve
Am using windows 8 n this issue got resolved by changing the environment variables
follow these steps:
Open my computer properties->advanced system settings->Environment variables.
Under 'system variables', select 'path' and click on 'edit'
In 'variable value', add 'C:\php;' OR the path where php installed.
click OK and apply the settings and restart the system.
It should work.
Here is a quick fix:
All the pros will probably hate me for this answer. But I got the same error on a server: Fatal error: Uncaught Error: Call to undefined function mysql_connect() that was using PHP 7. Did not have time to rewrite all the mysql code so a quick, temporary fix if anyone needs it is in CPANEL to look for PHP Configuration and change the version for that account to something like PHP 5.4 instead of PHP 7. Then the code worked fine without the above error.
If you are using Windows10, PHP 7.2 and try to connect to mysql.
If this error occurred
Uncaught Error: Call to undefined function mysqli() in
The do the following steps to get it correct.
Go to the PHP installation folder,
CHeck for php.ini file, (Only dev, prod file is there, then one of the file as php.ini file)
Look for "extension=mysqli" and remove the ";" before it.
Look for "extension_dir" and mentioned the path of "ext" directory.
Restart the application.
Hope this helps to someone.
Check if mysqli module is installed for your PHP version
$ ls /etc/php/7.0/mods-available/mysql*
/etc/php/7.0/mods-available/mysqli.ini /etc/php/7.0/mods-available/mysqlnd.ini
Enable the module
$ sudo phpenmod mysqli
This Code Can Help You
<?php
$servername = "localhost";
$username = "root";
$password = "";
$con = new mysqli($servername, $username, $password);
?>
But Change The "servername","username" and "password"
The problem shows up when you're using mysql_connect in your code lines so just add it as in mysqli_connect and it will solve the problem.
You also have to then use mysqli throughout your code lines or the problem would surface again.
The example mysql_select_db will then be mysqli_select_db for selecting Database.
I have the following code:
$username = 'username';
$password = 'password';
$host = 'localhost';
$db = 'dbname';
$dbh = new mysqli('p:'.$host, $username, $password, $db)
or die('no connection to server');
But I get the following error
PHP Warning: mysqli::mysqli() [<a href='function.mysqli-mysqli'>function.mysqli-mysqli</a>]: (HY000/2005): Unknown MySQL server host 'p:localhost' (1) in /var/www/vhosts/politiker.lu/httpdocs/includes/sql.php on line 8
This intrigues me because the very same code worked on my development environment. Now that I want to set it up on my production server, it does not work. Any ideas?
Note: I am not very good with servers, so excuse me if the error should be something trivial.
EDIT 1
Here are the versions:
Development PHP (5.3.3-1ubuntu9.1) + MySQL(5.1.49-1ubuntu8.1)
Production PHP (5.2.4-2ubuntu5.12) + MySQL(5.0.51a)
take out the p: like this:
$dbh = new mysqli($host, $username, $password, $db)
or die('no connection to server');
Just adding this since I didn't think it was clear, but the problem is definitely your production version of PHP. Persistent connections for the mysqli extensions weren't added until 5.3 since they caused headaches before.
Some hosts might have different versions of PHP installed... I realized today that I can make HostGator use PHP 5.3! I just had to add to my .htaccess file:
Action application/x-hg-php53 /cgi-sys/php53
AddType application/x-hg-php53 .php
i think you missed the mysqli package in this server. Try :
sudo apt-get install php5-mysqli
if apt-get says it is already installed try to do a ping to localhost, if don't resolve edit /etc/hosts and check the line where localhost points to 127.0.0.1
should be there, if not, your server its horribly configured!
do a
ifconfig
and check if you get some output like this...
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
You need to specify the actual location of the MySQL server. For development, it is localhost (most likely), just how you have it configured. But for production servers, it is going to be something else. I doubt it should be localhost.