php PDO parameter binding

Source: Internet
Author: User

* Data Sheet

--MySQL dump 10.16 distrib 10.1.31-mariadb, for osx10.6 (i386)----host:localhost Database:laravel-- --------------------------------------------------------Server version 10.1.31-mariadb/*!40101 SET @[email protected] @CHARACTER_SET_CLIENT*/;/*!40101 SET @[email protected] @CHARACTER_SET_RESULTS*/;/*!40101 SET @[email protected] @COLLATION_CONNECTION*/;/*!40101 SET NAMES UTF8*/;/*!40103 SET @[email protected] @TIME_ZONE*/;/*!40103 SET time_zone= ' +00:00 '*/;/*!40014 SET @[email protected] @UNIQUE_CHECKS, unique_checks=0*/;/*!40014 SET @[email protected] @FOREIGN_KEY_CHECKS, foreign_key_checks=0*/;/*!40101 SET @[email protected] @SQL_MODE, sql_mode= ' No_auto_value_on_zero '*/;/*!40111 SET @[email protected] @SQL_NOTES, sql_notes=0*/;----table structure for table ' users '--DROP TABLE IF EXISTS' users ';/*!40101 SET @saved_cs_client = @ @character_set_client*/;/*!40101 SET character_set_client = UTF8*/;CREATE TABLE' users ' (' ID 'int(Ten) unsigned not NULLauto_increment, ' name 'varchar(255) not NULL, ' email 'varchar(255) not NULL, ' password 'varchar( -) not NULL, ' Remember_token 'varchar( -)DEFAULT NULL, ' Created_at 'timestamp  not NULL DEFAULT '0000-00-00 00:00:00', ' Updated_at 'timestamp  not NULL DEFAULT '0000-00-00 00:00:00',  PRIMARY KEY(' id '),UNIQUE KEY' users_email_unique ' (' email ')) ENGINE=InnoDB auto_increment= A DEFAULTCHARSET=UTF8;/*!40101 SET character_set_client = @saved_cs_client*/;----dumping data for table ' users '--LOCK TABLES ' users ' WRITE;/*!40000 ALTER TABLE ' users ' DISABLE KEYS*/;INSERT  into' Users 'VALUES(1,'Mingzhanghui','[email protected]','123456',NULL,'2018-06-30 16:00:00','2018-07-12 16:00:00'),(2,'username#0','[email protected]','123456','Ed3d2c21991e3bef5e069713af9fa6ca','2018-07-21 09:28:37','2018-07-21 09:29:37'),(3,'username#1','[email protected]','123456','3416A75F4CEA9109507CACD8E2F2AEFC','2018-07-21 09:28:37','2018-07-21 09:29:37'),(4,'username#2','[email protected]','123456','43ec517d68b6edd3015b3edc9a11367b','2018-07-21 09:28:37','2018-07-21 09:29:37'),(5,'username#3','[email protected]','123456','182be0c5cdcd5072bb1864cdee4d3d6e','2018-07-21 09:28:37','2018-07-21 09:29:37'),(6,'username#4','[email protected]','123456','2a38a4a9316c49e5a833517c45d31070','2018-07-21 09:28:37','2018-07-21 09:29:37'),(7,'username#5','[email protected]','123456','ac627ab1ccbdb62ec96e702f07f6425b','2018-07-21 09:28:37','2018-07-21 09:29:37'),(8,'username#6','[email protected]','123456','2a38a4a9316c49e5a833517c45d31070','2018-07-21 09:28:37','2018-07-21 09:29:37'),(9,'username#7','[email protected]','123456','f033ab37c30201f73f142449d037028d','2018-07-21 09:28:37','2018-07-21 09:29:37'),(Ten,'username#8','[email protected]','123456','03AFDBD66E7929B125F8597834FA83A4','2018-07-21 09:28:37','2018-07-21 09:29:37'),( One,'username#9','[email protected]','123456','33e75ff09dd601bbe69f351039152189','2018-07-21 09:28:37','2018-07-21 09:29:37');/*!40000 ALTER TABLE ' users ' ENABLE KEYS*/; UNLOCK TABLES;/*!40103 SET [email protected]_time_zone*/;/*!40101 SET [email protected]_sql_mode*/;/*!40014 SET [email protected]_foreign_key_checks*/;/*!40014 SET [email protected]_unique_checks*/;/*!40101 SET [email protected]_character_set_client*/;/*!40101 SET [email protected]_character_set_results*/;/*!40101 SET [email protected]_collation_connection*/;/*!40111 SET [email protected]_sql_notes*/;--Dump completed on 2018-07-22 12:07:18
Users.sql

* PHP Code Snippet

<?php$settings = [' host ' = ' 127.0.0.1 ', ' port ' = ' 3306 ', ' name ' = ' laravel ', ' username ' = ' ro ' OT ', ' password ' = ', ' charset ' = ' utf8 '];try {$pdo = new PDO (sprintf (' mysql:host=%s            ;d bname=%s;port=%d;charset=%s ', $settings [' Host '], $settings [' name '], $settings [' Port '], $settings [' CharSet ']), $settings [' username '], $settings [' Password ']);}    catch (Pdoexception $e) {echo "Database Connection failed:". $e->getmessage (); Exit;} $sql = ' SELECT * from the users where email=:email '; $sql = ' select * from users where ID <: ID '; $statement = $pdo-&GT;PR Epare ($sql);//$email = Filter_input (input_get, ' email ');//$statement->bindvalue (': email ', ' [email  Protected] ', PDO::P aram_str), $statement->bindvalue (': Id ', 8, PDO::P aram_int); $statement->execute (); \/while ( ($result = $statement->fetch (PDO::FETCH_ASSOC))!== false) {//Echo $result [' emAil ']. php_eol;//}while (($o = $statement->fetchobject ())!== false) {echo $o->email. Php_eol;} transanction//$pdo->begintransaction ();//.//$pdo->commit ();

  

* Output

Chenhuimingdemacbook-pro:database mch$ PHP pdo.php

[Email protected]
[Email protected]
[Email protected]
[Email protected]
[Email protected]
[Email protected]
[Email protected]

php PDO parameter binding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.