����������
WEB - ������

www.spravkaweb.ru Rambler's Top100
 ï¿½ï¿½ ����������: �������/PHP/���� ������ MySQL.������ � ������ ������Ðàñïå÷àòàòü 
�������
�������
����� ���
HTML
JavaScript
VBScript
CSS
Flash
Perl
PHP
MySQL
SSI
VRML
�������������
������
Download
�����
��������
������
�������� ���
�����:
��������
Subscribe.Ru:

PHP

<--����� | ��������� � ������ | ������-->
���� ������ MySQL
������ � ������ ������
mysql_connect
������������� ������� ���������� � ����� ������ MySQL.

��������� :
int mysql_connect([string $hostname[:port][:/path/to/socket][, [,string $username [,string $password]]])

������� mysql_connect() ������������� ������� ���������� � ����� ������ MySQL, ������������� �� ����� $hostname, � ���������� ������������� ��������� ����������. ��� ���������� ������ ������� ������ � ���� ���������������. ��� ����������� ����������� ��� ������������ $username � ������ $password. ������ $hostname ����� ����� �������� � ���� ����� ����� � ���� "hostname:port"��� ���� � ������ ��� ��������� ������ � �������� Unix - ":/path/to/socket" (���� ������ MySQL �������� �� �� ������������, � �� �����-�� ������ ����).
��� ������ �������� ��������������. ������ ��������� �� ������ ����� �����������, ������ ����� ������ ������� �������� "@".
��� ��������� ������� ������� � ���� �� ������ ����������� ������ ���������� �� ����� �������, � ������� ��������� ������������� ��� �������������.
� ����� �������� ������ ������� ��������� ����������� �������� mysql_close(), �� ����� ����� �� ������, �.�. PHP ������������� ��������� ��� (������������) ����������� ��� ���������� ��������.
<?php
   $conn = mysql_connect ("localhost", "username", "pass")
        or die ("���������� �� �����������!");
   print ("���������� �����������!");
   mysql_close($conn);
?>

mysql_pconnect
������������� ���������� ������� ���������� � ����� ������ MySQL.

��������� :
int mysql_pconnect([string $hostname[:port][:/path/to/socket][, [,string $username [,string $password]]])

������� mysql_pconnect() ������������� ���������� ������� ���������� � ����� ������ MySQL, ������������� �� ����� $hostname, � ���������� ������������� ��������� ����������. ��� ���������� ������ ������� ������ � ���� ���������������. ��� ����������� ����������� ��� ������������ $username � ������ $password. ������ $hostname ����� ����� �������� � ���� ����� ����� � ���� "hostname:port"��� ���� � ������ ��� ��������� ������ � �������� Unix - ":/path/to/socket" (���� ������ MySQL �������� �� �� ������������, � �� �����-�� ������ ����).
��� ������ �������� ��������������. ������ ��������� �� ������ ����� �����������, ������ ����� ������ ������� �������� "@".
��� ��������� ������� ������� � ���� �� ������ ����������� ������ ���������� �� ����� �������, � ������� ��������� ������������� ��� �������������.
mysql_pconnect() ��������� ���������� mysql_connect, �� � ����� ���������:
  • ����� ������������ ������� �������� ���������, ������� �� ��� �������� �����������. ���� ����, �� ������������ ������������� ������ �������� ������ �����������.
  • ��� ���������� �������� ����������� �� �����������, � �������� ����������� ��� ����������� �������������, �.�. ������� mysql_close() �� ����� ������� �����������, ��������� � ������� mysql_pconnect().

  • mysql_close
    ��������� ������������� ����� ���������� � ����� ������.

    ��������� :
    int mysql_close ([int link_identifier])

    ��������� ���������� � MySQL ��������� � ��������������� link_identifier, ��� ��������� �������� ����������, ���� ������������ ��� ��������������.
    ���������� true ��� ������� �������� ��� false ��� ������.
    ������������� ���� ������� �� �����������, �.�. PHP ������������� ��������� ��� ������������ ����������� ��� ���������� ������ ��������.
    �����������, ������������� �������� mysql_pconnect(), �� �����������.
    <?php
       $conn = mysql_connect ("localhost", "username", "pass")
            or die ("���������� �� �����������!");
       print ("���������� �����������!");
       mysql_close($conn);
    ?>

    mysql_change_user
    �������� ��������� �����������.

    ��������� :
    int mysql_change_user(string user, string password [, string database [, int link_identifier]])

    ���� �� ����������� �� ��� �����������, �� ������������ ��������� �������� ��.
    ���� ����������� �� ���������, �� ��������� ����������� �� ����������.
    �������� � MySQL 3.23.3 � ����.

    mysql_list_dbs
    ���������� ������ �� �� �������.

    ��������� :
    int mysql_list_dbs([int link_identifier])

    ���������� ����� �������, ���������� ������ �� �� �������.
    $bd=mysql_connect("localhost", "name", "pass");
    $bd_list=mysql_list_dbs($bd);
    while($row=mysql_fetch_object($bd_list)) {
      echo $row->Database."\n";
    }
    ���� ��������, ��� ������ ��� ������ ����� �������� �� ���� ����������, �.�. �� ������� ������ �������.

    mysql_db_name
    ���������� ��� ���� ������ �� ������.

    ��������� :
    int mysql_db_name(int result, int row [, mixed field])

    �������� result ������ ���������� ������ �������, ���������� ��� ������ ������� mysql_list_dbs(). �������� row ��������� ����� ������.
    � ������� ������ ������ ������� ���������� false.
    mysql_connect("localhost", "username", "pass");
    $db_list=mysql_list();
    for($i=0;$i<($cnt=mysql_num_rows($db_list));$i++) {
      echo mysql_db_name($db_list,$i)."\n";
    }
    
    ����� ������� ���������� mysql_dbname().

    mysql_select_db
    ����� ����� ���� ������ MySQL.

    ��������� :
    int mysql_select_db (string database_name [, int link_identifier])

    ���������� true ��� ������� �������� ��� false ��� ������.
    ���� �� ���������� ��������� ������ ���� ���������� � ����� ������ �� ��� ����� ������ ��������, �� ������ �� ��������� ������������ ��������, � ����� �� ��������� ������������� ��� ������ ���� ��������� �������.
    �� ���� ��� ������� ������ ������ ������� MySQL, ���������� �������, � ����� ����� ������ �� ���������� ��������. ��� ����� � ������������� ������ �������. ��� ����������, ��� � ���������� ��������� � ����������� link_identifier (��� � ��������� �������� �����������, ���� ��������� �������� �� �����) ����� �������������� ���� ������ database_name.
    ���� �� ������ ������ ������ ������� ����������� � ���� ������ ���, �� �������� ���������� ������� mysql_connect() � ����������� �� ���������.

    mysql_create_db
    �������� ���� ������ MySQL.

    ��������� :
    int mysql_create_db(string dbname [, int link_identifier])

    ��� ������� ������� ����� ���� ������ MySQL � ������ dbname, ��������� ����������� link_identifier.
    $db=mysql_connect("localhost", "name", "pass");
    if(mysql_create_db("my_db_name")) {
      echo "�� my_db_name �������");
    } else {
      echo "������ �������� ��: %s\n".mysql_error());
    }

    mysql_drop_db
    �������� ���� ������ MySQL.

    ��������� :
    int mysql_drop_db(string database_name [, int link_identifier])

    ������� mysql_drop_db() ������� ���� ������ database_name, ��������� � ����������� link_identifier.
    � ������ ��������� �������� ���������� true, ��� ������ - false.

    mysql_list_tables
    ���������� ������ ������ � ��.

    ��������� :
    int mysql_list_tables(string database [,int link_identifier])

    ������� ���������� ������������� ���������� (���� �������), � ������� ����������� ����� ���� ������, �������������� � ���� ������. ��� ���������� ���� ���� ����� ������������ ������� mysql_result() � ������� �������, ������ 0, ��� ������� mysql_tablename().

    ��������� ������ ������� ��� ����� ��� ������ � ������, ������� � ��� �����������:
    $db=mysql_connect("localhost", "user_name", "");
    $db_list=mysql_list_dbs($db);
    while($r_db=mysql_fetch_object($db_list)) {
      echo $r_db->Database."\n";
        // ����������� ������ ������
      $t_list=mysql_list_tables($r_db->Database);
      for($i=0;$i<mysql_num_rows($t_list);$i++) {
        echo " - ".mysql_tablename($t_list,$i)."\n";
      }
    }

    mysql_tablename
    ���������� ��� ������� � ��.

    ��������� :
    int mysql_tablename(int result, int i)

    ������� ���������� ��� ������� � ������� i �� ������ �������, ���������� ��� ������ ������� mysql_list_tables().
    $db=mysql_connect("localhost", "user_name", "");
    $result=mysql_list_tables("db_name");
    $i=0;
    while($i<mysql_num_rows($result)) {
      $t_name[$i]=mysql_tablename($result, $i);
      echo $t_name[$i]."<BR>";
      $i++;
    }
    

    mysql_query
    �������� ������ ���� ������ MySQL.

    ��������� :
    int mysql_query(string query [,int link_identifier])

    ��� ������� �������� ������ query ���� ������, ��������� � ��������������� link_identifier ���� ������������� �� ������, �� ����������� �� �������� ��������� �������� ����������. ���� �� ����� ���������� ������ �����������, �� ����������� �������� mysql_connect() � ����������� �� ���������.
    SQL-���������, ��������� � ��������� query, �� ������ ������������ ";".
    ���� ��������� �������� ������, ��� ��� ���������� �������� � �������, �� ������� mysql_query() ���������� false.
    � ���������� ������� ������������ ������� ������������ ����� �������, ������� ����� ���������� ���������� ���������:
  • mysql_result() - �������� ������� ������ �������
  • mysql_fetch_array() - ������ ������ � ������
  • mysql_fetch_row() - ������� ������ � ������������ ������
  • mysql_fetch_assoc() - ������� ������ � ������������� ������
  • mysql_fetch_object() - ������� ������ � ������

    ����� ������, ������� ������� ���� ������� �������� SELECT, �������������� �������� mysql_num_rows().
    ��� ����, ����� ������, ������� ������� ���� �������� � ���������� ���������� �������� DELETE, INSERT, REPLACE ��� UPDATE, �������������� �������� mysql_affected_rows().

    ����� ��������� ����������� ������� �� ����� ���� ������ �������� mysql_free_result(). �� � ���� ��� �������������, �.�. ���������� ���� ������������ ����� ���������� ������ ��������.

  • mysql_db_query
    �������� ������ � ��������� ���� ������ MySQL.

    ��������� :
    int mysql_db_query(string database, string query [,int link_identifier])

    ��� ������� ������������ ��������� ������������������ �������:

    mysql_select_db(string database [, int link_identifier]);
    mysql_query(string query [, int link_identifier]);

    mysql_num_rows
    ���������� ���������� ����� � ���������� �������.

    ��������� :
    int mysql_num_rows(int result)

    ��� ������� ���������� ����� �������, ��������� � ���������� ���������� SQL-������� SELECT (����� �� ���� ������).
    <?
    $link = mysql_connect("localhost", "username", "password"); 
    mysql_select_db("database", $link);
    
    $result = mysql_query("SELECT * FROM table1", $link); 
    $num_rows = mysql_num_rows($result); 
    
    echo "�������� �����: $num_rows\n";
    ?>
    

    mysql_affected_rows
    ���������� ���������� ���������� ������� � �� MySQL.

    ��������� :
    int mysql_affected_rows([int link_identifier]);

    ������� mysql_affected_rows() ���������� ���������� �������, ������� ���� �������� � ���� ������ � ���������� ���������� �������� DELETE, INSERT, REPLACE ��� UPDATE.
    ���� ��������� �������� ���� ������� DELETE ��� ����������� WHERE (�.�. �� ������� ���� ������� ��� ������), �� ���� ������� ��������� 0.

    mysql_insert_id
    �������� ����������� �������������.

    ��������� :
    int mysql_insert_id([int $link_identifier])

    ������� ���������� ��������������� ����� �� ������� ��������������� ������������� ������ ��� ����������������� ���� ����� ���������� ������� insert. �������� �� ������� ������ ����� ����� ���������� ���������� insert, ��������, � ����� ���������:

    mysql_query("insert into �������(���� 1, ���� 2) values("aa","bb")");
    $id=mysql_insert_id();

    ������ � ������ ��� ����������� ������ ����� ����������, ��������� ������������� $id:

    $r=mysql_query("select * from ������� where id=$id");
    $Row=mysql_fetch_array($r);

    mysql_data_seek
    ������������� ��������� ������� ������.

    ��������� :
    int mysql_data_seek(int result, int row_number)

    ��� ������� ������������� ��������� ������� ������ � ���������� result � ������� row_number, ��� ��� ��������� ����� mysql_fetch_row() � mysql_fetch_array() ������ �������� ����� ������ ���� ������.
    ��������� ������� ������� � 0.
    ���������� false � ������ ������ ��� ���� ������ ���������.

    mysql_free_result
    ���������� ����� �������.

    ��������� :
    int mysql_free_result(int result)

    ������ ������� ����������� ������, ���������� ������� ������� result, ������������ ��������.
    ��� ������� ����������, ����� ����� ��������� ������, �.�. PHP ������������� ����������� ������ ��� ���������� ��������.
    �� ���������� ����� ����� ������� "PHP 4. ����������� ����������."
    www.piter.com
    ������ / � ����������
     
    Download
    Ñêà÷àòü ñïðàâî÷íèê ïî PHP
    ��� ������:
    05.07.2004
  • � ������� PHP ��������� ��������� ������� ��� ������ � ���������� (���������� GD):
    imagetypes(), ...
  • � ������� JavaScript ��������� �������� �� ����� D, E, F, H, I
  • � ������� ������ ��������� ������, �������������� ��� �������� � html-�������� ��������� MS Office (Word, Excel � �.�.)
  • �����������:
    ��� ��� ������ ����� �� �������� � �����������:
    ��� ��������.
    ������ �� ��������.
    ���� ��������.
    �������� �������� �������.
    �� ��� ������� �������.
    � ����������� ���� ������.
    � ��� ��� �����.
    ������.
    ��������:
    Rambler's Top100
    Ñäåëàòü ñòðàíèöó ñòàðòîâîé ������� �������� ���������
    Äîáàâèòü ñòðàíèöó â èçáðàííîå �������� ���� � ���������
    Ñîîáùèòü îá íàéäåííîé îøèáêå �������� �� ������