/    Sign up×
Community /Pin to ProfileBookmark

PHP Version 5.6.40, internal error for connect mysql

According to I have a project need to use PHP 5.6.40 connect to mysql version 5.7.34
This URL for phpinfo()
[](https://http://newlink.bdb.com.la/app/webroot/test.php)

when I try to connect it by below coding

[code]$servername = “localhost”;
$username = “user”;
$password = “pass”;
$db_database = ‘db_unelr’;
$db_port = ‘3306’;

// Create connection
$conn = mysqli_connect($servername, $username, $password,$db_database,$db_port);

// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
echo “Connected successfully”;[/code]

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 05.2021 — Note, I edited your post to wrap the code in this forum's ... tags for better readability.
Copy linkTweet thisAlerts:
@NogDogJun 05.2021 — What gets output after "Connection failed:" -- or does it even reach that line?
Copy linkTweet thisAlerts:
@NitiphoneauthorJun 05.2021 — I tried it but still got error message below
Fatal error: Call to undefined function mysql_connect() in /home/newlinkbdbcom/public_html/app/webroot/test.php on line 5
Copy linkTweet thisAlerts:
@NitiphoneauthorJun 05.2021 — [https://newlink.bdb.com.la/app/webroot/test.php](https://) this is the phpinfo

it's because mysql driver or something?
Copy linkTweet thisAlerts:
@NitiphoneauthorJun 06.2021 — [root@host etc]# grep extension=php_mysqli.dll php.ini

[root@host etc]# grep extension=php_mysql.dll php.ini

extension=php_mysql.dll

[root@host etc]#

I try to use this code

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');<br/>
if (!$link) {<br/>
die('Could not connect: ' . mysql_error());<br/>
}<br/>
echo 'Connected successfully';<br/>
die();


but I got the error message

Fatal error: Call to undefined function mysql_connect() in /home/newlinkbdbcom/public_html/app/webroot/test.php on line 4
Copy linkTweet thisAlerts:
@NitiphoneauthorJun 06.2021 — I try many command but always get the same error message.

maybe it's because mysql service?
Copy linkTweet thisAlerts:
@NogDogJun 06.2021 — Looks like neither the MySQL nor the MySQLi extension is installed/enabled on your web server. You only need one or the other, with MySQLi being the preferred, more modern version -- or you could use the PDO extension with its MySQL driver if available. (I personally much prefer to use PDO.) You could test PDO with something like:
[code=php]
$servername = "localhost";
$username = "user";
$password = "pass";
$db_database = 'db_unelr';
$db_port = '3306';

$dsn = "mysql:host=$servername;port=$db_port;dbname=$db_database";
try {
$pdo = new PDO($dsn, $username, $password);
} catch (PDOExeception $e) {
error_log($e->getMessage());
die("DB Connection failed");
}
[/code]
Copy linkTweet thisAlerts:
@NitiphoneauthorJun 07.2021 — @NogDog#1632615 Yes, I really need to use mysql function for using my project's script.

How can I fix it?
Copy linkTweet thisAlerts:
@NogDogJun 07.2021 — Are you working on a web server under someone else's control (in which case you need to talk with them), or are you just working in a local environment on your own computer, or...? The environment being used and how PHP is installed there will drive what needs to be done (and I'm not an installation expert).
Copy linkTweet thisAlerts:
@NitiphoneauthorJun 07.2021 — @NogDog#1632621 It's private hosting. so I can run any command on it
Copy linkTweet thisAlerts:
@NogDogJun 07.2021 — If Ubuntu Linux, you could try:
<i>
</i>sudo apt-get install php5-mysql
# omit the "sudo" if logged in as root

...and then restart the web server. No promises. If it's a Centos flavor of Linux, you'd use yum instead of apt-get, and the package might have a different name. See https://www.howtoforge.com/apache_php_mysql_on_centos_6.5_lamp for some possibly useful info.
Copy linkTweet thisAlerts:
@elipalmJun 08.2021 — What gets output after "Connection failed" or does it even reach that line?
×

Success!

Help @Nitiphone spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...