PHP for循环错误!

时间:2011-03-05 08:24:42

标签: php mysql sql

嗨,这是我的代码,我无法弄清楚什么是错的?

<?PHP
$my_connection = mysql_connect('localhost', 'root', 'password');

for (!$my_connection){
    die("Could not connect" . mysql_error());
}

echo "Conected sucessfully" . "<br>";

mysql_select_db('killer');

mysql_close($my_connection);
?>

2 个答案:

答案 0 :(得分:5)

修订后的代码

<?php
    $my_connection = mysql_connect('localhost', 'root', 'password');
    if (!$my_connection)
        die("Could not connect" . mysql_error());
    echo "Conected sucessfully <br/>";
    mysql_select_db('killer');
    mysql_close($my_connection);
    ?>

答案 1 :(得分:4)

for替换为if,应该这样做