search
HomeBackend DevelopmentPHP ProblemWhat should I do if php cannot connect to the database?

php cannot connect to the database because PHP7 has abandoned the connect method and cannot connect to the database. The solution is to use the mysqli method to connect to the database.

What should I do if php cannot connect to the database?

The operating environment of this article: Ubuntu16 system, PHP7.0 version, DELL G3 computer

PHP cannot connect to the database?

I used the connect method to connect to the database successfully, but now it fails. The code is as follows:

<?php
$con = mysql_connect("localhost","root","code");
if (!$con)
{
die(&#39;Could not connect: &#39; . mysql_error());
}
mysql_close($con);
?>

My Ubuntu is version 16 and PHP is 7.0. Finally, I found that PHP7 has abandoned the connect method and used PDO and mysqli instead. I switched to the mysqli method and it was successful. For specific operations, please see the tutorial below:

PDO:

//m.sbmmt.com/php/php-pdo .html

Mysqli:

//m.sbmmt.com/php/php-ref-mysqli.html

The above is the detailed content of What should I do if php cannot connect to the database?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),