You are not logged in.

#1 2022-06-21 08:24:57

orange_lizzard
Member
Registered: 2022-06-21
Posts: 3

PHP not connecting to MariaDB

I am new to LAMP and PHP so be easy on me. I am trying to setup a LAMP stack I get this error when running the php script:

[vagrant@arch http]$ php index.php
 PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in /srv/http/index.php:3
Stack trace:
#0 {main}
  thrown in /srv/http/index.php on line 3

This is the script

 <?php

mysql_connect('127.0.0.1', 'root', '');

?>

More information:

[vagrant@arch http]$ php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
hash
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

I have installed the packages php, apache, php-apache, mariadb, and configured them according to the MariaDB, php, Apache wiki pages. The system is up-to-date and has been restarted.

Any help would be greatly appreciated

Last edited by orange_lizzard (2022-06-21 08:41:22)

Offline

#2 2022-06-21 08:34:16

Maniaxx
Member
From: .de
Registered: 2014-05-14
Posts: 622

Re: PHP not connecting to MariaDB

Probably deprecated.
https://www.php.net/manual/en/function. … onnect.php

Follow Arch first:
https://wiki.archlinux.org/title/PHP#MySQL/MariaDB

Last edited by Maniaxx (2022-06-21 08:41:55)


sys2064

Offline

#3 2022-06-21 08:38:31

orange_lizzard
Member
Registered: 2022-06-21
Posts: 3

Re: PHP not connecting to MariaDB

yep. I guess I should find a more up-to-date tutorial. Thanks a ton.

Offline

#4 2022-06-21 08:39:00

mpan
Member
Registered: 2012-08-01
Posts: 850
Website

Re: PHP not connecting to MariaDB

You are calling `mysql_connect`. That function belonged to a module that has been completely removed 7 years ago. To access databases PHP offers PDO, with the “pdo_mysql” module providing the backend for MySQL and MariaDB. There is also mysqli, but that extension has uses with very specific circumstances — when you must interface with MySQL client API more or less directly for specific, precisely defined features.

Since circumstances suggest you are just starting programming in PHP: whatever source you learn from and even suggested going near the `mysql_*` family of functions, stop using it instantly. It’s garbage. Not merely outdated: teaching that module was a horrible idea even before it has been removed from PHP.

Also, please consider changing the subject: you swapped “MariaDB” and “PHP”. That will confuse other people searching for help. :D

Last edited by mpan (2022-06-21 08:41:55)


Sometimes I seem a bit harsh — don’t get offended too easily! PGP: 7C848198AE93D3BB

Offline

#5 2022-06-21 08:45:47

orange_lizzard
Member
Registered: 2022-06-21
Posts: 3

Re: PHP not connecting to MariaDB

thanks mpan, will do. Yep trash tutorial off YouTube. Funny thing is it's only like 2 years old. I thought it would be an okay jumping off point but yeah total trash. Can you recommend any guides to php for someone just starting out?

Offline

#6 2022-06-21 09:25:21

mpan
Member
Registered: 2012-08-01
Posts: 850
Website

Re: PHP not connecting to MariaDB

Unfortunately I myself can’t. Too long since I had a need for one.

But I see that the official documentation has a PDO tutorial: connecting, prepared statements and transactions. Statements which take no parameters are done using query method (Ctrl+F “example”). In general most answers at Stack Overflow are at least of decent value and those should teach you how to handle basic use cases.


Sometimes I seem a bit harsh — don’t get offended too easily! PGP: 7C848198AE93D3BB

Offline

Board footer

Powered by FluxBB