MYSQL: Limit Word Length for MySql Insert
every search query is saved in my database, but I want to Limit the Chracterlength for one single word: odisafuoiwerjsdkle --> length too much --> dont write in the database
my actually code is:
$search = $_GET['q'];
if (!($sql = mysql_query ('' . 'SELECT * 开发者_如何学PythonFROM `history` WHERE `Query`=\'' . $search . '\''))) {
exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
;
}
while ($row = mysql_fetch_array ($sql)) {
$ID = '' . $row['ID'];
}
if ($ID == '')
{
mysql_query ('' . 'INSERT INTO history (Query) values (\'' . $search . '\')');
}
if (!($sql = mysql_query ('SELECT * FROM `history` ORDER BY `ID` ASC LIMIT 1')))
{
exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
;
}
while ($row = mysql_fetch_array ($sql)) {
$first_id = '' . $row['ID'];
}
if (!($sql = mysql_query ('SELECT * FROM `history`')))
{
exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
;
}
One option would be using a trigger in the table. But, if you are expecting a lot of traffic on your search engine it might not scale very well. So, using client side (PHP in your case) constraints might be a better choice.
精彩评论