search
Homephp教程php手册绑定列,列王的纷争账号绑定

绑定列,列王的纷争账号绑定

<?<span>php
    </span><span>try</span><span>{
        </span><span>$dbh</span> = <span>new</span> PDO('mysql:dbname=testdb;host=localhost', 'mysql_user', 'mysql_pwd'<span>);
        </span><span>$dbh</span>->setAttribute(PDO::ATTR_ERRMODE, PDO::<span>ERRMODE_EXCEPTION);
    }</span><span>catch</span>(PDOException <span>$e</span><span>){
        </span><span>echo</span> '数据库连接失败:'.<span>$e</span>-><span>getMessage();
        </span><span>exit</span><span>;
    }
  
    </span><span>//</span><span>声明一个SELECT查询,从表contactInfo中获取D01部门的四个字段的信息</span>
    <span>$query</span> = "SELECT uid, name, phone, email FROM contactInfo WHERE departmentId='D01'"<span>;
    </span><span>try</span><span> {
        </span><span>$stmt</span> = <span>$dbh</span>->prepare(<span>$query</span>);                      <span>//</span><span>准备声明好的一个查询</span>
        <span>$stmt</span>->execute();                           <span>//</span><span>执行准备好的查询</span>
        <span>$stmt</span>->bindColumn(1, <span>$uid</span>);                    <span>//</span><span>通过列位置偏移数绑定变量$uid</span>
        <span>$stmt</span>->bindColumn(2, <span>$name</span>);                              <span>//</span><span>通过列位置偏移数绑定变量$name</span>
        <span>$stmt</span>->bindColumn('phone', <span>$phone</span>);                        <span>//</span><span>绑定列名称到变量$phone上</span>
        <span>$stmt</span>->bindColumn('email', <span>$email</span>);                 <span>//</span><span>绑定列名称到变量$email上</span>

        <span>while</span> (<span>$stmt</span>->fetch(PDO::FETCH_BOUND)) {                <span>//</span><span>fetch()方法传入特定的参数遍历</span>
            <span>echo</span> <span>$uid</span>."\t".<span>$name</span>."\t".<span>$phone</span>."\t".<span>$email</span>."\n";    <span>//</span><span>输出自动将列值赋给对应变量的值</span>
<span>        }
    } </span><span>catch</span> (PDOException <span>$e</span><span>) {
        </span><span>echo</span> <span>$e</span>-><span>getMessage();
    }</span>

 

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

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

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.