QA公开课:QA就业趋势 知识班第1课:2010.06.12 QA介绍和基础知识 项目班第1课:2010.06.12 Web B/S架构
2010年6月-8月软件测试课程安排 知识班第2课:2010.06.19 SDLC/Testing Process 项目班第2课:2010.06.19 构建LAMP lab
恭喜一下L同学正式签约RIM(2010年4月) 知识班第3课:2010.07.10 Test plan & Test case 项目班第3课:2010.07.10 LAMP练习
性能测试和LoadRunner课程简介 知识班第4课:2010.07.17 bug流程和管理 项目班第4课:2010.07.17 SRS Review meeting
恭喜一下又一位M同学正式找到QTP自动测试的工作(2010年5月) 知识班第5课:2010.07.24 使用QC管理测试 项目班第5课:2010.07.24 Test Case Design练习
庆祝又一位新L同学(女)跳槽成功(10年6月) 知识班第6课:2010.08.07 QTP(1) 项目班第6课:2010.08.07 Test Case 课堂练习
第一位年薪十万的同学终于冒出来了(10年8月) 知识班第7课:2010.08.07 QTP(2) 项目班第7课:2010.08.14 Test plan和总结
2010.8月双喜临门,又一位同学找到测试新工作(10年8月) 知识班第8课:QA常用的windows命令和工具
返回列表 回复 发帖

A Few MySQL Tips You Might Not Know

MySQL is a database server suitable for small and a little bigger sized database applications. It has been the all time favourite since its creation. It works on windows as well as Unix / Linux but when run on Unix / Linux, it can provide multithreading which boosts its performance a lot. MySQL supports standards SQL (ANSI) and can be used with a variety of web technologies pretty efficiently. PHP with MySQL is one of the best combinations used by millions of websites and they are happy with it. And the beauty of both PHP and MySQL is that they are open source meaning FREE!! In this article I will describe a few MySQL functions, some of them I had been desperate for back at some point in my web development journey.
Last Inserted Row Number

Often when working with multiple tables, you run an INSERT query on a table and then you need to find out its ID in order to be able to use it to update another table. I used to use the MAX function to perform this until I found this useful function called mysql_insert_id. This function, when given the link identifier, retrieves the AUTO_INCREMENT ID of the last INSERT operation. Below is an example of how it can be used:

    // Insert query for a table with an AUTO_INCREMENT field named order_id
    // the values for the rest of the fields product name, quantity, price
    //are being inserted

    $ins_qry = "INSERT INTO orders values (‘Umbrella','2','50')";

    //Run the query myConn represents the connetion string

    $qryresource = mysql_query($ins_qry, $myConn);

    // Get the inserted ID

    $inserted_id = mysql_insert_id($myConn);

    // $inserted_id now contains the id for the last inserted row

NOTE: If the link identifier is not specified, the last link opened by mysql_connect() is assumed.
FULLTEXT Search

When working with searches on text fields in MySQL, the LIKE queries are very commonly used. The situation gets complicated when it comes to using them on large tables. MySQL now provides an alternative, which is easy to use and more efficient. The FULLTEXT can create indexes of CHAR, VARCHAR and TEXT fields and organise them efficiently. It can also return a relevance value based on how well each result matched the words a user is looking for. To CREATE a table and ask MySQL to start indexing a field or set of fields you would write something like this:

CREATE TABLE articles (
    ->   article_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    ->   title VARCHAR(200),
    ->   body TEXT,
    ->   FULLTEXT (title,body)

You can also ALTER an existing table to start building an index of some of the columns:

    ALTER TABLE articles ADD FULLTEXT art_search (title, body)

You will then need to INSERT or MODIFY a record to get MySQL start indexing it. With the FULLTEXT indexing turned on you can use the MATCH() function to search for a string against the columns included. By default the search is not case-sensitive but you can change it by using a binary collation. The following SELECT statement will return all indexes in the title and body columns against the word "MySQL database", along with the relevance score of each result:

    SELECT id, body, MATCH (title,body) AGAINST
        -> ('MySQL Database') AS score
        -> FROM articles WHERE MATCH (title,body) AGAINST
        -> ('MySQL Database');

The MySQL FULLTEXT implementation regards any sequence of true word characters (letters, digits, and underscores) as a word. That sequence may also contain apostrophes ('), but not more than one in a row.

For more reading on the FULLTEXT features please refer to the MySQL manual at http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Stop Injection Attacks

The user input mechanism in online forms and the way it is handled by the code has a potential for abuse. This techniques used by the hackers is called SQL Injection Attacks. The attacks can be more dangerous if you are using a database other than MySQL. The reason being MySQL does not allow more than one statemnts in a single call. The attack can cause serious problems in some situations like online authentication systems if not handled properly. In a typical example of authenticating a user through a provided Login ID and Password, you would normally have something like this:

    // userid and pwd are the field names posted by the user

    SELECT * from users WHERE
    userid='" . $_POST['userid'] . "'
    AND
    password='". $_POST['pwd'] ."'

    // Get the results and check if any match is found
    // Authenticate the user if match is found

Using the SQL Injection Attack a hacker can enter:

    OR userid LIKE '%'

Taking this value as an input, your query will become:

    SELECT * from users
    WHERE userid=' ' AND password=' ' OR username LIKE '%'

This will cause the above query to select all records from the table resulting in authenticating the user.

To avoid this problem you need to escape the incoming variables as shown below:

    SELECT * from users
    WHERE userid='" . safeEscapeString($_POST['userid']) . "'
    AND
    password='". safeEscapeString($_POST['pwd']) ."'

I am sure this would only cost you a little more time but trust me its worth applying it anywhere you get data from users using a web interface.

For further reading on this topic please refer to the following URLs

http://www.sitepoint.com/article/sql-injection-attacks-safe
http://www.unixwiz.net/techtips/sql-injection.html
是的,我们不但要顶,我们还要马上顶,顶一篇对不起楼主,我们就顶两篇,两篇不行我们就顶三篇。我们不但自己要顶,这样的好贴我们要发动更多的人来顶。
















淘宝女装皇冠店 淘宝女装皇冠店铺 淘宝皇冠店铺大全 淘宝皇冠卖家
今天天气不错么 就是冷了一点。字都打不出来了。




















义乌二手网(www.cnyiwu.net)
一个火红的事 一个良心的产业孩童教育市场
我们是来自台湾最新的科技教育技术公司
我们寻求大陆地区加盟伙伴
想投资创业给你一个零风险、稳赚的事业
潜能测评,商机无限
目标体群体基数庞大市场前景无可限量
投资教育""途无量
个人测评/加盟咨询热线
13764055537颜主任
请重新输入以下网址连结 www.mitq.net

皮纹多元智能测试,皮指纹多元智能测试,皮纹多元智能测评,皮指纹多元智能测评,皮纹测评,皮指纹测评,皮纹测试,皮指纹测试,台湾MITQ,上海MITQ,皮指纹,皮纹
返回列表