MAMP:不能做MySQL查询

Some background: I initially tried doing Apache, MySql, and PHP on windows, each installed separately (what a PITA that was!). Eventually I heard that I would be better suited on the mac, so I got the MAMP.

Glad to find that everything has been installed, I try playing around with it. Basically everything works, except for MySQL queries (I am trying to insert data into a table).

Here's my code:

<h1>hello world</h1>
<?php
echo "hello ";
echo date('H:i:s, jS F Y');
$link = mysql_connect('localhost', 'root', 'root');
if ($link)
    echo "success";
else
    echo "failure";

$db_selected = mysql_select_db('MyDB', $link);
if ($db_selected) 
    echo "success";
else
    echo "failure";

$my_query = mysql_query($link,"INSERT INTO comments (cName, cComment)
VALUES ('Peter', 'Hellloooooo')");

if ($my_query)
    echo "success";
else
    echo "failure";

mysql_close($link);
?>

My output looks like the following:

hello world

hello 00:14:12, 19th March 2013successsuccessfailure

As you can see, mysql_connect and mysql_select_db work, but mysql_query does not. I've spent many fruitless hours trying to figure this out. What is wrong with the code?

Try

$my_query = mysql_query("INSERT INTO comments (cName, cComment)
VALUES ('Peter', 'Hellloooooo')", $link);

Next time better mysqli or PDO.

Updated: Mysqli: U need to create mysqli connection

$mysqli = mysqli_connect("host", "user", "password", "database");
$stmt = $mysqli->prepare("INSERT INTO comments(cName, cComment) VALUES (?, ?)");

$name = 'Peter';
$comment = 'Haloooo';
$stmt->bind_param("ss", $name, $comment);
$stmt->execute();