我想在使用php 5.3插入之前检查表中是否已存在URL。在使用php 5.3插入之前检查MySQL行中的数据
+-------------+-----------+ + durl + surl + +-------------+-----------+ + abc + xyz + + mno + pqr + + efg + jkl + +-------------+-----------+
如果我加abc它给我存储在col 2 [surl] xyz中的值。
如果不在数据库中添加此项。
<?php
$dbhost = '****';
$dbuser = '****';
$dbpass = '****';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
$query="select * from new where durl = tmp";
$result = mysql_query($query);
if (mysql_num_rows($result)>0) {
// return value of col 2
}
else {
$sql = 'INSERT INTO new '.
'(durl,surl) '.
'VALUES ("tmp", "XYZ")';
mysql_select_db('a4806808_my');
$retval = mysql_query($sql, $conn);
mysql_close($conn);
}
?>
什么是你的问题.. ?? –
但mysql_num_rows在php 5.3中给出了一个错误 – Nilay