Click to See Complete Forum and Search --> : [RESOLVED] Sanity check on mutiple query


Major Hooters
04-12-2007, 02:14 PM
Hey all,

mysql version 5.20, php 5

I just need a sanity check that what I am doing is not going to cause problems down the road. So any suggestions would be helpful. What I am doing is making multiple sql querys like this:


@ $db = new mysqli('localhost', 'blah', 'blah', 'blah');
$sql = "update sdata set description='".$description."' where refnum=" .$refnum;
$sql2 = "update sdata set datetime=now() where refnum=" .$refnum;
$result = $db->query($sql);
$result2 = $db->query($sql2);

if($result === FALSE)
{
die("Query failed: $sql <br>\n".$db->error);
}
if($result2 === FALSE)
{
die("Query failed: $sql2 <br>\n".$db->error);
}
if ($result and $result2)
{
*echo something back saying success!*
}
}
$result->free();
$result2->free();
$db->close();


Any Comments?? thanks!

aj_nsc
04-12-2007, 02:19 PM
Yeah you're right, you do need a sanity check :P

just do this:

$sql = "update sdata set description='".$description."', datetime=now() where refnum=" .$refnum;
$result = $db->query($sql);

Major Hooters
04-12-2007, 02:28 PM
Thanks!

That also works and looks cleaner. However the engineer in me wants to know why the other way might cause problems. Was it just a cleaner way of doing things or was some type of protocol being broke? Just curious! thanks again!!
8)

aj_nsc
04-12-2007, 02:29 PM
cleaner and shorter.

Major Hooters
04-12-2007, 02:30 PM
Cool, thanks again!