. .

    @Mail.ru -

MySQL

» PHP 5 » MySQL

. , . , book. INSERT INTO ( 12.5).

12.5. .

‹html›
‹head›
‹title› ‹/title›
‹/head›
‹body›
‹?php
$sdb_name = "localhost";
$user_name = "root";
$user_password = "";
$db_name = "test_db";
//
if (!$link = mysql_connect($sdb_name, $user_name, $user_password))
{
  echo "‹br›He ‹br›";
  exit();
}
//
if (!mysql_select_db($db_name, $link))
{
  echo "‹br›He ‹br›";
  exit();
}
//
$str_sql_query = "INSERT INTO book (name, author, num_pages) VALUES (' PHP','','222')";
//
if (!mysql_query($str_sql_query, $link))
{
  echo "‹br›He ‹br›";
  exit();
}
echo "‹br› ‹br›";
//
mysql_close($link);
?›
‹/body›
‹/html›

, book л, , 222. , id . , AUTO_INCREMENT ( ). , , . .

, . , .

SQL- DELETE. :
DELETE FROM book WHERE author = ''

, DELETE FROM (book), , .

UPDATE. :
UPDATE book SET num_pages = 333 WHERE name = ' PHP'

UPDATE , . ( , 222 333) .

, . , . . , .

, , book ( 12.6).

12.6. .

‹html›
‹head›
‹title› ‹/title›
‹/head›
‹body›
‹?php
$sdb_name = "localhost";
$user_name = "root";
$user_password = "";
$db_name = "test_db";
//
if (!$link = mysql_connect($sdb_name, $user_name, $user_password))
{
  echo "‹br›He ‹br›";
  exit();
}
//
if (!mysql_select_db($db_name, $link))
{
  echo "‹br›He ‹br›";
  exit();
}
//
$str_sql_query = "SELECT * FROM book";
//
if (!$result = mysql_query($str_sql_query, $link))
{
  echo "‹br›He ‹br›";
  exit();
}
//
while ($mas = mysql_fetch_row($result))
{
  foreach ($mas as $field)
  {
    echo $field . " ";
  }
  echo "‹br›";
}
//
mysql_close($link);
?›
‹/body›
‹/html›

, , . , - . , . . PHP mysql_connect(), (localhost), . source, , .

mysql_select_db(). . , TRUE, - FALSE.

. . SQL- mysql_query(). $result.

, , . - mysql_fetch_row(), , . while. mysql_fetch_row() .