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.

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('Could not connect: ' . 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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

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),






