2012年9月11日星期二

PHP and MYSQL




PHP from DB using SQL in conjunction with this connection should be helping to function .. There are a lot of

, Let's learn about these functions.

Encyclopedia by default MYSQL and Oracle or MSSQL through their corresponding functions
Try to find hope.

1 mysql_connect
2 mysql_select_db
3 mysql_query
4 mysql_num_rows
5 mysql_fetch_array
6 mysql_error
7 mysql_fetch_assoc
8 mysql_fetch_row
9 mysql_num_field
10 mysql_close
Using PHP with DB yijeongdo only given to understand, will not interfere.

The example below, so the association could build description to avoid confusion ^ ^

mysql_connect function

Function prototypes: mysql_connect ("hostname: port", "id", "password")

Example]
  $ Connect = mysql_connect ("localhost: 3306", "test", "1234");
  if (! $ connect) {
    echo "in the SQL connection failed ...";
    exit;
  }
  echo is normally connected to SQL "..";

Role that connect to the sql php from sql db save or to extract various materials used to link this function.

Arguments in a function prototype, an important role to connect to SQL.

First, the host: port => Average SQL port number 3306, but sometimes security issues due to the inevitable problems
            Must designate a case is used to arbitrarily change the port number if the port number you want one
            Connection is made, the leak.
            So, usually most of the hostname only when the port number is not 3306, but note: the port number
            Will like to put ...

Second, id => id this sort of account name used to connect to the SQL ID
           SQL can be used, subject to approval from the administrator.
           Otherwise approved private server, but if you can create your own, you want to administrators
           Generated by and give them the id name approved or specified by the administrator receives grant ID
          Please will

Third, password => Similarly, access to the SQL account username and password for the key.
            This key is also granted or approved by the Administrator receives

※ The above example was done properly the ground connection is normally made at the door will be maenteu output
    Otherwise, the output has failed maenteu ..

mysql_select_db

Function prototypes: mysql_select_db ("DB", a resource variable name);

Example]
   $ Selectdb = mysql_select_db ("TESTDB", $ connect);


 This function is allowed access to the account used to connect to the database access by using the link connected to the SQL function.

 Access to the database (DB hereafter), and it should maintain the space inside the table to create, modify or delete various data input and extraction will be

Granted with the argument from the first argument, DB names used in function prototypes be granted when the account yourself to use SQL is one of the space.

Flexible; connection value variable resource variable name when the sql connection is successful, the second argument means $ connect is usually used, but according to the developers, please refer

mysql_query

Function prototypes: mysql_query (SQL query "content" [resource variable name])

Example]
    $ Query = "select * from test_table";
    $ Result = mysql_query ($ query [, $ connect]);

   This function is connected to SQL server and send SQL commands to the resource value, depending on the success seonggongin his return form
   When an empty string is passed as a receive failure .. The return values ​​are stored in the $ result if used alone.
   Will not be returned.

   Note: By default, if one link that exists only on the SQL server $ connect and you can skip, and
            If you must designate the presence of multiple link can be processed normally.
            If you do not specify to use the first link connected to fails or because you do not want
            May result in careful ..

mysql_num_rows

Function prototypes: mysql_num_rows (resource variable name)

Example]
       $ Row_num = mysql_num_rows ($ result);


   SQL to query depending on the number of records that are extracted from the mysql_query function, this function return the number that
   Function.

   Test_table all bring a record, according to the query that was used in the above example, the function mysql_query
   Because it is the number of records imported 10 $ row_num this function to define the value of 10 variables.


    Note: This function returns the number 0 or unusual queries by resource value of the variable is empty if
    Errors can occur.
    Error Warning Error error due to the unusual query, if the query using mysql_query to take a look at the value of
    Precautions and otherwise using the @ hide the error message.

mysql_fetch_array

Function prototypes: mysql_fetch_array (resource variable name)

Example]
    $ Row = mysql_fetch_array ($ result);
    echo $ row [name];
 

   This function, the value returned is the array returned by the SQL query using the mysql_query function.

   Output test_table of the first record of the name field in the above example, the contents of the output.

   You want to output the contents of a field, if you are a large number of records, if used in conjunction with a loop, the number of records loaded
   Record, which is one of the cases, without the need to use a loop output.

mysql_error

This function is a function that returns the contents of the SQL working error that occurs with the print statement if you use
Variables defined in the error output and allows returns.

mysql_fetch_assoc

This function returns the value of the field as an associative array, unlike mysql_fetch_row

Ie $ row = mysql_fetch_assoc ($ result); when,
    If no, name, memo to assume that the field in the SQL table name $ row [no], $ row [name]
    $ Row [memo] will return only jumyeo available.

    Fetch_row and that is returned from the function described above mysql_fetch_array an array of values ​​that can be used for both,
    This function is handled by all, and if you think a function that returns a faster speed.

mysql_fetch_row

This function mysql_fetch_assoc function differently from a function that returns an array of numbers.
Assoc from above mentioned field name is present when the return is returned 0-2 and each number
Will be filled with the contents of each field.
, And assoc array address is a number that is returned to the character to think that if you are returned.

mysql_num_fields

This function is a function that returns the number of fields in a table returned by a SQL query.
Otherwise, multiple records of a loop statement, if and when used in conjunction as a stand-alone.

Example]
    / / Test_table field assumes the existence of three fields and no, name, memo
   Returns 3 / / mysql_query example of this comes to accept mysql_num_fields

   $ Query = "select name, memo from test_table";

  If you give the / / SQL query will return 2 ...


mysql_close

Breaking as a function of the link connected to the SQL function SQL> shutdown function is called.

That link to the resource variable anymore since I use this function to be used to access SQL will not ...


Note: The above notation for function prototypes did not function, the function name (resource variable name) .. is culminated in a circular fashion


PHP functions related to SQL over Balb The information below is a summary of some terms.

Presence of a small amount of space the field: the value of one
Record: field gathered in one of the small group
Table record from a large group of
Database table from a large group

Could be defined as're easier

Field and recorded on a sheet of paper,
Record means a sheet of paper has been written
Means the table is placed a sheet of paper tied to a sheet of file folders,
This folder to temporarily store the database ... You will find bookshelves
You will find the SQL to stand for keeping this bookcase ..

Stand to bookshelf suits you if you try to escape, and that the range of viewing and recording rights to the administrator.
Rights will be assigned stop

没有评论:

发表评论