Home Backend Development PHP Tutorial PHP simple database connection program_PHP tutorial

PHP simple database connection program_PHP tutorial

Jul 13, 2016 am 10:46 AM
mysql php No database of program Simple kind connect

A good and simple database connection program. Students who need php mysql database connection class can refer to this article.

The code is as follows
 代码如下 复制代码


require_once("mssql.class.php");
//1.创建类,并连接数据库
$db = new mssql("dns=aaa;uid=sa;pwd=sa;dbname=test");
//2.连接数据库
$conn = $db->config("dns=aaa;uid=sa;pwd=sa;dbname=test");
//3.选择数据库
$dbname = $db->select_db("test");
//4.设置允许调试
$db->debug = true;
//5.执行一条不返回结果的SQL语句
$db->execute("insert into test01(name) values('这是一个测试!')");
//$db->exec("");
//6.执行一条返回结果的SQL语句
$rs = $db->query("select * from test01");
//7.以row方式显示结果
echo "
以row方式显示结果集
";
while($r = $db->fetch_row($rs)){
 echo $r[0].":".$r[1]."
";
}

//8.以array方式显示结果
$rs2 = $db->query("select * from test01");

echo "
以array方式显示结果集
";
while($r = $db->fetch_array($rs2)){
 echo $r["id"] . ":" . $r["name"] . "
";
}

//X.释放
$db->db_close();

?>


 

Copy code

require_once("mssql.class.php");
//1. Create a class and connect to the database
$db = new mssql("dns=aaa;uid=sa;pwd=sa;dbname=test");
//2. Connect to database
$conn = $db->config("dns=aaa;uid=sa;pwd=sa;dbname=test");
//3.Select database
$dbname = $db->select_db("test");
//4.Set to allow debugging
$db->debug = true;
//5. Execute a SQL statement that does not return a result
$db->execute("insert into test01(name) values('This is a test!')");
//$db->exec("");
//6. Execute a SQL statement that returns results
$rs = $db->query("select * from test01");
//7. Display the results in row format
echo "
Display the result set in row format
";
while($r = $db->fetch_row($rs)){
echo $r[0].":".$r[1]."
";
}

//8. Display the results in array format
$rs2 = $db->query("select * from test01");

//X. Release
$db->db_close();
?>
http://www.bkjia.com/PHPjc/632932.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632932.htmlTechArticleA good and simple database connection program. Students who need php mysql database connection class can refer to this article. The code is as follows Copy the code ?PHP require_once(mssql.class.php); //1. Create...
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

CakePHP Creating Validators

See all articles