Call to undefined function mysql_connect after upgrade to Moodle 3.6 [duplicate] - moodle

This question already has answers here:
Fatal error: Uncaught Error: Call to undefined function mysql_connect()
(9 answers)
Closed 3 months ago.
I have ran aptitude install php5-mysql (and restarted MySQL/Apache 2), but I am still getting this error:
Fatal error: Call to undefined function mysql_connect() in /home/validate.php on line 21
phpinfo() says the /etc/php5/apache2/conf.d/pdo_mysql.ini file has been parsed.

In case, you are using PHP7 already, the formerly deprecated functions mysql_* were removed entirely, so you should update your code using the PDO-functions or mysqli_* functions instead.
If that's not possible, as a workaround, I created a small PHP include file, that recreates the old mysql_* functions with mysqli_*()-functions: fix_mysql.inc.php

I see that you tagged this with Ubuntu. Most likely the MySQL driver (and possibly MySQL) is not installed. Assuming you have SSH or terminal access and sudo permissions, log into the server and run this:
sudo apt-get install mysql-server mysql-client php5-mysql
If the MySQL packages or the php5-mysql package are already installed, this will update them.
UPDATE
Since this answer still gets the occasional click I am going to update it to include PHP 7. PHP 7 requires a different package for MySQL so you will want to use a different argument for the apt-get command.
# Replace 7.4 with your version of PHP
sudo apt-get install mysql-server mysql-common php7.4 php7.4-mysql
And importantly, mysql_connect() has been deprecated since PHP v5.5.0. Refer the official documentation here: PHP: mysql_connect()

Well, this is your chance! It looks like PDO is ready; use that instead.
Try checking to see if the PHP MySQL extension module is being loaded:
<?php
phpinfo();
?>
If it's not there, add the following to the php.ini file:
extension=php_mysql.dll

If someone came here with the problem of docker php official images, type below command inside the docker container.
$ docker-php-ext-install mysql mysqli pdo pdo_mysql
For more information, please refer to the link above How to install more PHP extensions section(But it's a bit difficult for me...).
Or this doc may help you.
https://docs.docker.com/samples/library/php/

I was also stuck with the same problem of undefined MySQL_connect().I tried to make changes in PHP.ini file but it was giving me the same error.
Then I came to this solution where I changed my code from depreciated php functions to new functions.
$con=mysqli_connect($host,$user,$password);
mysqli_select_db($con,dbname);
//To select the database
session_start(); //To start the session
$query=mysqli_query($con,your query);
//made query after establishing connection with database.
I hope this will help you .
This solution is correctly working for me .
EDIT:
If you upgrade form old php you need to apt-get install php7.0-mysql

Try:
<?php
phpinfo();
?>
Run the page and search for mysql. If not found, run the following in the shell and restart the Apache server:
sudo apt-get install mysql-server mysql-client php5-mysql
Also make sure you have all the following lines uncommented somewhere in your apache2.conf (or in your conf.d/php.ini) file, from
;extension=php_mysql.so
to
extension=php_mysql.so

In php.ini file
change this
;extension=php_mysql.dll
into
extension=php_mysql.dll

My guess is your PHP installation wasn't compiled with MySQL support.
Check your configure command (php -i | grep mysql). You should see something like '--with-mysql=shared,/usr'.
You can check for complete instructions at http://php.net/manual/en/mysql.installation.php. Although, I would rather go with the solution proposed by #wanovak.
Still, I think you need MySQL support in order to use PDO.

The question is tagged with ubuntu, but the solution of un-commenting the extension=mysqli.dll is specific to windows. I am confused here?!, anyways, first thing run <? php phpinfo ?> and search for mysql* under Configuration heading. If you don't see such a thing implies you have not installed or enabled php-mysql. So first install php-mysql
sudo apt get install php-mysql
This command will install php-mysql depending on the php you have already installed, so no worries about the version!!.
Then comes the unix specific solution, in the php.ini file un-comment the line
extension=msql.so
verify that msql.so is present in /usr/lib/php/<timestamp_folder>,
ELSE
extension=path/to/msql.so
Then finally restart the apache and mysql services, and you should now see the mysql section under Configrations heading in phpinfo page

I was getting this error because the project I was working on was developed on php 5.6 and after install, the project was unable to run on php7.1.
Just for anyone that uses Vagrant with ubuntu/nginx, in the nginx directory(/etc/nginx/), there is a directory named "sites-available" which contains a file named like the url configured for the vagrant maschine. In my case was homestead.app. Within this file there is a line that says something like
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
There you can change the php version to the desired for that particular site.
Googled this but wasnt really able to find a simple answer that said where to look and what to change.
Hope that this helps anyone.
Thanks.

If you are getting the error as
Fatal error: Call to undefined function mysql_connect()
Kindly login to the cPanel >> Click on Select Php version >> select the extension MYSQL

For CentOS 7.8 & PHP 7.3
yum install rh-php73-php-mysqlnd
And then restart apache/php.

(Windows mysql config)
Step 1 : Go To Apache Control Panel > Apache > Config > PHP.ini
Step 2 : Search in Notepad (Ctrl+F) For: ;extension_dir = "" (could be commented with a ;). Replace this line with: extension_dir = "C:\php\ext" (please do not you need to remove the ; on the beginning of the sentence).
Step 3 : Search For: extension=php_mysql.dll and remove the ; in the beginning.
Step 4 : Save and Restart You Apache HTTP Server. (On Windows this usually done via a UI)
That's it :)
If you get errors about missing php_mysql.dll you'll probably need to download this file from either the php.net site or the pecl.php.net. (Please be causius about where you get it from)
More info on PHP: Installation of extensions on Windows - Manual

There must be some syntax error. Copy/paste this code and see if it works:
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect:' . mysql_error());
}
echo 'Connected successfully';
?
I had the same error message. It turns out I was using the msql_connect() function instead of mysql_connect().

Related

Bootstrap failed: 5: Input/output error while running any service on macOS Big Sur version 11.5.2

I am trying to run mongodb-community#4.2 service using brew services start mongodb-community#4.2 (facing similar error, while running httpd service or any other service)
Following is the error:
Error: Failure while executing; /bin/launchctl bootstrap gui/502 /Users/chiragsingla/Library/LaunchAgents/homebrew.mxcl.mongodb-community#4.2.plist exited with 5.
There can be multiple reasons behind this error message. So, the first thing to do is to find where your mongo related logs are stored. To do that, run the following command -
sudo find / -name mongod.conf
This will get you the mongo db config file. On running this command, I got /usr/local/etc/mongod.conf. You may find it directly under /etc.
On opening mongod.conf, you will find log path mentioned there. You can open the file itself, or instead get the last 15-20 lines of this log file via tail command -
tail -n 15 <<your mongo db log path>>
Now, you will need to debug the issue mentioned in the logs. Generally, I have seen these three sets of issues -
Permission issue with /tmp/mongodb-27017.sock - While some SO answers asked to change the permissions for this file as a solution, my issue with this only went away after I removed this file.
Compatibility issue - If you see a message like Version incompatibility detected, it means that the mongodb version you have currently installed is different from the version whose data is present on your system. Uninstall the current mongodb version and then install the correct older version (if you don't want to lose the data).
Once you have done it, and your mongo is up and running, and you want to upgrade mongodb version, follow this SO answer.
Permission issues with WiredTiger - Using chmod to change file permissions resolved these.
In case you have any issue other than these three, you will still need to search more on SO and figure it out. Hope this was of some help! :)

Upgrading postgres 9.5 to 11

So ive been tasked of upgrading our postgres server to version 11, however all the guide ive found either dont work for me or are not complete.
I have tried 2 methods and had to recall all changes:
https://www.hutsky.cz/blog/2019/02/upgrade-postgresql-from-9-3-to-11/
In this method not only are the dependency checks and upgrade commands exactly the same but also none of these commands work for me, i keep getting the error of:
"You must identify the directory where the new cluster binaries reside.
Please use the -B command-line option or the PGBINNEW environment variable.
Failure, exiting"
And ive been unable to find any fix to this.
And also tried the delete old method :
https://techcyclist.com/postgres/upgrading-postgres-to-the-latest-version-on-centos-7-server/
but in this method he deletes the old postgres completely and also the config files, but our config files have been made by the EX sys admin and i simply dont have the time it takes to study the configs to redo them in the new version, and i cant risk simply replacing the new config file with the ole one.
If anyone has done such a assignment and is willing to help, i would much appreciate it.
I used : yum install postgresql11 postgresql11-contrib postgresql11-devel postgresql11-libs postgresql11-server
to install the new postgres 11 and :
/usr/pgsql-11/bin/initdb -D /var/lib/pgsql/11/data
to init it. with a few dependencies installing in between.
afterwards all other commands :
/usr/pgsql-11/bin/pg_upgrade --old-bindir=/usr/pgsql-9.3/bin/ --
new-bindir=/usr/pgsql-11/bin/ --old-
datadir=/var/lib/pgsql/9.3/data/ --new-
datadir=/var/lib/pgsql/11/data/ --check
gave errors as described.

Understanding the error message: spdlog::spdlog_ex

I am aware this question is very specific. Nontheless, maybe s.o. can help:
I was trying to compile an open-source code today. (anyone, who's interested, that's the one.) The error message described below occurs after oai_hss -j $PREFIX/hss_rel14.json --onlyloadkey - having followed the step-by-step installation guide to this point.
After typing the aforementioned command in my terminal, the following error is thrown:
terminate called after throwing an instance of 'spdlog::spdlog_ex'
what(): Failed opening file logs/hss.log for writing: No such file or directory
Aborted (core dumped)
Allright, this sounds pretty severy (core dumped). I was searching google for a meaning of that error message. I came across this other github project. Apparently the spdlog class is trying to enable logging from wherever I run my program. And it throws an spdlog_ex error whenever the file it is trying to add to the registry (in this case logs/hss.log) already exists within this registry. So, I guess, the solution to my problem would be to find this registry and delete logs/hss.log. Does this make sense?
Question: Where the heck do I find this registry?
Maybe some background knowledge would be useful: I am trying to compile the open-source code within a VM that is running Ubuntu 18.04.3 LTS bionic with a 4.15.0-66-generic kernel.
I was searching the /tmp directory for a log folder already. There is none. Where else could it be?
open this file
sudo nano /usr/local/etc/oai/hss_rel14.json
you will see some config where you can find logs/hss.log
actually you have to change these 4 value to
logname: "/var/log/hss.log"
statlogname: "/var/log/hss_stat.log"
auditlogname: "/var/log/hss_audit.log"
ossfile: "~/openair-cn/etc/oss.json"
then use sudo touch to create these files
sudo touch /var/log/hss.log
sudo touch /var/log/hss_stat.log
sudo touch /var/log/hss_audit.log
for logname, statlogname, and auditlogname you can change it to whatever file you want but i like to put them together in /var/log folder.
for ossfile , the oss.json is actually in there.
hope this help

Could not find driver (PDO exception with Laravel)

I have researched this problem extensively and I have tried everything that has been suggested, but I think I may have missed something. I have a laravel project with the following configuration for .env:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=oamileage
DB_USERNAME=postgres
DB_PASSWORD=********
I have also uncommented the following line in php.ini:
;extension=pdo_pgsql -> extension=pdo_pgsql
I get the following error when I try to use php artisan migrate:
Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)
A side note: I already have pgsql up and running for another project of mine (which is unrelated to laravel) and it's working without a problem. I am on windows.
I have my PDO drivers installed, as seen here:
It seems that the php cli has another config file installed elsewhere (the path can be found in phpinfo()). I uncommented the following line, according to madflow and it worked:
;extension=pdo_pgsql -> extension=pdo_pgsql
You just need to install:
sudo apt-get install php7.2-pgsql
After the previous command you can migrate your models to database:
php artisan migrate

CakePhp 3 : server php not found

i'm trying cakephp v3 for a test, so i have install cake with composer, and i can't launch the server as requested by the tutorial.
When i do bin/cake server in the app folder, i get this response:
bin/cake: line 39: exec: php not found
I tried with ./bin/cake but it's the same.
For information, i have wamp on my computer and the authorization for bin are rwxr-xr-x.
Any idea on how fix it?
Thanks for your help
You may need to add the PHP directory to your path. On the command line (e.g. in a batch file), it would look like this:
SET PATH=%PATH%;C:\your\wamp\path\php
if in doubt, it's the directory containing the php.exe.