Home > Backend Development > PHP Tutorial > How to connect to database with PHP MySQL

How to connect to database with PHP MySQL

WBOY
Release: 2016-07-25 08:54:57
Original
1246 people have browsed it
  1. $con = mysql_connect("localhost","peter","abc123");

  2. if (!$con)
  3. {
  4. die('Could not connect: ' . mysql_error());
  5. }

  6. // some code

  7. ?>

Copy code

Close connect Once the script ends, the connection is closed. To close the connection early, use the mysql_close() function.

  1. $con = mysql_connect("localhost","peter","abc123");
  2. if (!$con)
  3. { bbs.it-home.org
  4. die('Could not connect: ' . mysql_error());
  5. }

  6. // some code

  7. mysql_close($con);

  8. ?>

Copy code


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template