我使用这样的东西:
$url_title = mysql_real_escape_string($_GET['title']);
$sql = dbquery("SELECT * FROM `videos` WHERE `post_name` = '$url_title' LIMIT 0, 1");
/* or this old one
$local_id = ($_GET['id'];
$sql = dbquery("SELECT * FROM `videos` WHERE `id` = '$local_id' LIMIT 0, 1");
// for urls like :
// example.com/video/music/red-hot-chili-peppers-californication-564/
*/
$num_rows = mysql_num_rows($sql);
if ($num_rows == "0"){die();}
while($row = mysql_fetch_array($sql)){
$local_id = $row["id"]; // PRIMARY KEY ; auto increment
$video_id = $row["youtube_id"]; // Unique
$title = $row["name"]; // Unique
$name_slug = $row["name_slug"]; // Unique
// some more code
}
// and this one for urls like :
// example.com/video/music/red-hot-chili-peppers-californication/
我想问的是:
当我在db中而不是“564”查询“red-hot-chili-peppers-californication”时,服务器负载是否正常?
所有字段的类型都是varchar,除了$ id,它是int。
答案 0 :(得分:2)
我认为这是正常的。比较字符串比比较字符串更容易。在每种编程语言中。
答案 1 :(得分:1)
全部取决于您如何为mysql列设置type