国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home 類庫下載 PHP類庫 PHP uses mysqli extension to connect to MySQL database

PHP uses mysqli extension to connect to MySQL database

Oct 09, 2016 pm 01:06 PM

This article mainly introduces PHP to use the mysqli extension to connect to the MySQL database. Friends who need it can refer to it

1. Object-oriented usage

$db = new mysqli('localhost', 'root', '123456', 'dbname');

If the database is not specified when establishing the connection, select the database to use and switch to use Database

$db->select_db('dbname');
  
$query = "SELECT * FROM user WHERE uid=4";
  
$result = $db->query($query);
  
$result_num = $result->num_rows;
  
$row = $result->fetch_assoc();  //返回一個關(guān)聯(lián)數(shù)組,可以通過$row['uid']的方式取得值
  
$row = $result->fetch_row();  //返回一個列舉數(shù)組,可以通過$row[0]的方式取得值
  
$row = $result->fetch_array();  //返回一個混合數(shù)組,可以通過$row['uid']和$row[0]兩種方式取得值
  
$row = $result->fetch_object();  //返回一個對象,可以通過$row->uid的方式取得值
  
$result->free();  //釋放結(jié)果集
  
$db->close();  //關(guān)閉一個數(shù)據(jù)庫連接,這不是必要的,因為腳本執(zhí)行完畢時會自動關(guān)閉連接

When performing INSERT, UPDATE, and DELETE operations, use $db->affected_rows to view the number of affected rows

2. Process-oriented usage

$db = mysqli_connect('localhost', 'root', '123456', 'dbname');

If the database is not specified when establishing a connection, the database will be selected. Database, switch the database used

mysqli_select_db($db, 'dbname');

Query the database

$query = "SELECT * FROM user WHERE uid=4";
  
$result = mysqli_query($db, $query);
  
$result_num = mysqli_num_rows($result);

Return one row of results

$row = mysqli_fetch_assoc($result);  //返回一個關(guān)聯(lián)數(shù)組,可以通過$row['uid']的方式取得值
  
$row = mysqli_fetch_row($result);  //返回一個列舉數(shù)組,可以通過$row[0]的方式取得值
  
$row = mysqli_fetch_array($result);  //返回一個混合數(shù)組,可以通過$row['uid']和$row[0]兩種方式取得值
  
$row = mysqli_fetch_object($result);  //返回一個對象,可以通過$row->uid的方式取得值

Disconnect the database

mysqli_free_result($result);  //釋放結(jié)果集
  
mysqli_close($db);  //關(guān)閉一個數(shù)據(jù)庫連接,這不是必要的,因為腳本執(zhí)行完畢時會自動關(guān)閉連接

When performing INSERT, UPDATE, DELETE operations, use mysqli_affected_rows() to view the number of affected rows

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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276