PHP5.2中PDO的简单使用
【PDO配置】
1、确保PHP版本为5.2.5以上(主要是我用的5.2.5,第一次不知道用的5.1.x的,结果一直搞不好~_~)
2、在php.ini中找到Dynamic Extensions扩展部分,去掉extension=php_pdo.dll前面的分号
3、去掉相应数据库PDO扩展前面的分号,如:extension=php_pdo_mysql.dll
【范例中数据库】
CREATE TABLE tablename (
id mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT,
str varchar(50) NOT NULL DEFAULT '''',
PRIMARY KEY (id)
);
【程序范例】
/*
* 数据库配置信息
*/
$dsn = "mysql:host=localhost;dbname=test";
$user = ''root'';
$passwd = ''123456'';
/*
* 链接数据库,并测试是否链接成功
*/
try{
$db = new PDO($dsn, $user, $passwd);
}catch (PDOException $e)
{
echo "链接数据库失败!";
print "异常信息: ". $e->getMessage() . "
";
print "异常文件: " . $e->getFile() . "
";
print "异常行号: " . $e->getLine() . "
";
exit();
}
/*
* 插入
*/
//$sql = "INSERT INTO tablename SET str = ''Hello''";
//$count = $db->exec($sql); //返回值为影响的行数
/*
* 删除
*/
//$sql = "DELETE FROM tablename WHERE str = ''Hello'' LIMIT 1";
//$count = $db->exec($sql); //返回值为影响的行数
/*
* 查询
*/
//预处理需要查询的SQL语句
//$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); //列名按照原始的方式(字段)
$sql = "SELECT * FROM tablename WHERE id $query = $db->prepare($sql); //预处理
//用一组绑定参数执行一遍查询
$query->execute(array('':id''=>1, '':string''=>''Hello'')); //处理语句(参数绑定方式)
//$query->setFetchMode(PDO::FETCH_ASSOC); 关联数组形式(只通过字段名下标访问数组内容)
while($item =

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros
