I got this problem when I run php code to connect with database in mysql.. Can anybody help me? I'm stuck.
Error:
fatal error call to undefined function mysql_connect() in php
Php code:
?php
mysql_connect("localhost","root","") or die("Could not connect to database");
mysql_select_db("dadadsdb") or die("Could not select database");
?>
mysql_* functions are deprecated in newer PHP versions and in PHP 7 they are just gone. If you are using PHP 5.x you could install these modules by sudo apt-get install php-mysql (sometimes it is sudo apt-get install php5-mysql but I recommend you to use mysqli or PDO.
Use mysqli instead of mysql.
$con = mysqli_query("host","username","password","database");
Mysql has been deprecated in PHP 5.5 for various reason and it can be replaced with MySQLi OOP(Object Oriented Programming) or the normal procedural style.
You can also use PDO that is more secure than MySQL.
Related
This question already has answers here:
How can I enable the MySQLi extension in PHP 7?
(8 answers)
Closed 6 years ago.
I get an error when trying to connect to my database with mysqli on PHP 7.0 and PHP 7.1
PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /home/mywebsite/public_html/connection.php:7
$conn = mysqli_connect($DBhost,$DBuser,$DBpass,$DBname);
First check, if mysqli is enabled: phpinfo()
The mysqli PHP extension is not installed on your server. Contact to your server administrator.
OR
If you host the server yourself, in the php.ini file remove the semicolon in front of the extension extension=php_mysqli.dll.
Hope, this helps you
I would recommend using PHP PDO for database connection. Its got better performance and I think the code looks better.
But to speak on your error, it looks like php doesnt have a reference to mysqli library. Did you explicitly install the php-mysql package? Its also possible that the environment variable path is not pointing to the right location on the filesystem.
Your php not instaled mysql connector ,
for install linux :
sudo install php-mysqli
Happens when php extensions are not being used by default.
In your php.ini file, change
;extension=php_mysql.dll
to
extension=php_mysql.dll.
The mysqli PHP extension is not installed on your new server.
Contact to your server administrator.
If you host the server yourself, in the php.ini file remove the semicolon in front of the extension extension=php_mysqli.dll
http://php.net/manual/en/function.sybase-connect.php is removed as from PHP7.
So now I am gettings this error:
PHP Fatal error: Uncaught Error: Call to undefined function sybase_connect()
How am I supposed to connect to sybase now with PHP7?
You are using Ubuntu 16.04, so after installation of php7.0-sybase package in your system, you are able to connect with Sybase database using pdo_dblib
Example #1 PDO_DBLIB DSN examples
sybase:host=localhost;dbname=testdb
Following general PDO reference, you create connection like this
$databaseHandler = new PDO('sybase:host=localhost;dbname=testdb', $user, $pass);
My code is executing properly on development. But on production gives following error:
Missing Database Connection
Error: A Database connection using "Mysql" was missing or unable to connect.
The database server returned this error: Selected driver is not enabled
Error: Mysql driver is NOT enabled
Mysql extension on PHP 5.5.x and above is deprecated.
On PHP 7 mysql has been removed.
You should use PDO. If you can't, then try to replace your mysql with mysqli extension.
I got the same error, but it resolved with this
yum install --enablerepo=remi,remi-php70 php-mysqlnd
I am using WampServer Version 2.2, php5.4.3 , Apeache2.2.22 I could not use mssql_connect(), "mssql_connect() Fatal error: Call to undefined function mssql_connect()" I went through googling but still not found solution.
It is always better to use PDO which supports ms sqlserver and other databases, you can use the syntax
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
or you can refer the documentation https://secure.php.net/manual/en/pdo.connections.php
You don't have the MS SQL Drivers installed. You can check this with phpinfo();
On Linux you need mssql.so or sybase.so With debian its apt-get install php5-sybase
For windows take a look here
Drivers need to be configured for PHP to find the function
mssql_...
You could also look at PDO DB classes as they can connect to any DBS, you need the drivers installed tho.
I'm trying to connect to mysql server using the following code:
$connection = mysql_connect("localhost", "username", "password");
if(!$connection)
{
die('Could not connect: '. mysql_error());
}
And I'm getting "Call to undefined function mysql_connect()". Why is that? isn't this function built in in php?
I'm using Ubuntu 12.04 + php 5.4.11 + php's built in http server.
First do not use mysql_* functions as those functions are deprecated
and second you need to install php5-mysql
sudo apt-get install php5-mysql
and then you can use mysqli and also PDO (needs to be installed too).
You must enable the extension.
Be aware that this API is deprecated.