栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

学习从哪里准备语句的选择

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

学习从哪里准备语句的选择

您好ButterDog让我逐步引导您完成PDO。

步骤1)

创建一个名为connect.php的文件(或任何您想要的文件)。每个需要数据库交互的PHP文件中都需要此文件。

让我们开始也请注意我的评论:

?php//We set up our database configuration$username="xxxxx"; // Mysql username$password="xxxxx"; // Mysql password// Connect to server via PHP Data Object$dbh = new PDO("mysql:host=xxxxx;dbname=xxxxx", $username, $password); // Construct the PDO variable using $dbh$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set attributes for error reporting very importANT!$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); // Set this to false so you can allow the actual PDO driver to do all the work, further adding abstraction to your data interactions.?>

步骤2)需要connect.php,请看一下:

require ('....../........./...../connect.php'); // Require the connect script that made your PDO variable $dbh

第三步

要开始数据库交互,只需执行以下操作,还请阅读代码注释。目前,我们将不再担心数组!充分利用PDO,然后担心使其更容易使用!通过重复,“漫长的路要走”对代码有了更多的了解。一开始不要走捷径,一旦您了解自己在做什么,就把它们砍掉!

$query = $dbh->prepare("SELECt * FROM note_system WHERe note = :cnote"); // This will call the variable $dbh in the required file setting up your database connection and also preparing the query!$query->bindParam(':cnote', $cnote); // This is the bread and butter of PDO named binding, this is one of the biggest selling points of PDO! Please remember that now this step will take what ever variable ($cnote) and relate that to (:cnote)$query->execute(); // This will then take what ever $query is execute aka run a query against the database$row = $query->fetch(PDO::FETCH_ASSOC); // Use a simple fetch and store the variables in a arrayecho $row['yourvalue']; // This will take the variable above (which is a array) and call on 'yourvalue' and then echo it.

多数民众赞成在所有PDO。希望能有所帮助!

也看看这个。那对我有很大帮助!

我有时也将其用作参考-
该网站看起来像废话,但那里有关于PDO的质量信息。我也用这个,我发誓这是最后一个链接!因此,在此之后,您只需问任何问题,但希望它可以成为有关PDO的一些参考指南。(希望大声笑)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/400699.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号