Home  >  Article  >  Backend Development  >  There are several ways to modify the database in PHP

There are several ways to modify the database in PHP

angryTom
angryTomOriginal
2019-10-26 14:34:262790browse

There are several ways to modify the database in PHP

There are several ways to modify the database in PHP

In the PHP development process, we need to connect to the database to develop dynamics There are usually four ways to connect to a database on a website: Mysql-connect(),Mysqli,PDO,ADODB, we can use this How to connect to the database in 4 to modify the database will be introduced one by one next.

Mysql_connect

This is the first database connection method we encountered when we first started learning PHP. The connection result can be returned through the mysql_connect() function, then a MySQL connection identifier, returns FALSE if failed. Therefore, subsequent database modification operations can be performed.

 

This connection method is a short connection, not a long connection. If the connection is long, use mysql_pconnectct()

Mysqli

This is a The object-oriented database connection method requires instantiating an object before connecting, and then performing database operations through this object.

query($sql);
    while($row=$result->fetch_row($result)){
        echo  "$row";
    }
      }else{
        die("无法连接数据库".mysql_error());
      }

mysqli is a long connection method and is more secure than mysql_connect

PDO

What is pdo, pdo is added to the php5 center The way to connect to the database,

 query($sql);
              foreach($result as $k){
                    print_r($k);
              }
            }catch(PDOException $e){
                       echo $e->getMessage();
            }
    ?>

ADODB

No matter what the back-end database is, the way to access the database is the same, and developers don’t have to settle for a certain set of Database, you must learn another set of different access methods, which greatly reduces the knowledge burden of developers. Past knowledge can still be used in the future

require_once './adodb5/adodb.inc.php';
  $conn = &ADONewConnection('mysql');
  $conn->connect('localhost','root','','test');
  $conn->Execute("set names utf8");
  $res = $conn->Execute("select * from user");
  if (!$res){
     echo $conn->ErrorMsg();
  }else{
     var_dump($res);
   }

For more PHP related knowledge, please visitPHP中文网!

The above is the detailed content of There are several ways to modify the database in PHP. 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