search
Homephp教程php手册PHP远程连接MySQL数据库失败之原因

PHP远程连接MySQL数据库失败之原因

Jun 06, 2016 pm 07:53 PM
mysqlphpreasonfaildatabaseRemotelyconnect

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 php远程连接mysql数据库的步骤如下: 1.使用所购买空间的数据库管理界面,设置远程访问IP,也就是php文件所在的主机IP. 2.php文件中的数据库连接代码如下: $con = new mysqli($host, $user, $passwd

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  php远程连接mysql数据库的步骤如下:

  1.使用所购买空间的数据库管理界面,设置远程访问IP,也就是php文件所在的主机IP.

  2.php文件中的数据库连接代码如下:

  $con = new mysqli($host, $user, $passwd, $database);

  $host:数据库所在主机的IP,这里需要注意的是有的资料说在IP之后需要有"3306"这个端口号,但是我经过测试发现,加上端口号之后反而连接失败,所以这里不需要加端口号。

  当用php连接本地数据库时,令$host = 'localhost'即可,也不需要加端口号。

  $user:用户名

  $passwd:密码

  $database:数据库名

  3.执行php文件即可成功连接到数据库

  另外再补充一点,就是直接使用mysql命令远程连接到数据库:

  mysql -h $host -P 3306 -u $user -p

  回车后输入密码即可连接成功

PHP远程连接MySQL数据库失败之原因

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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment