Manual of PHP

 
 
 

Web map

 
rim   rim
Carriedarrow Connection with MySQL

 

Connection with MySQL To print E-mail

Once we have already explained a little superficially all the possible and logical operations that we can do with a database in the language SQL, there comes the moment to combine it with the PHP potency and for it we will use the program MySQL.

MySQL is one of the agents of databases more used in environments in which PHP is used since PHP has numerous functions that are combined perfectly with MySQL. The generic way of obtaining stage information in Mysql is the following one:

- Connection with the agent.
- Preparation of the consultation SQL.
- Execution of the consultation.
- Prosecution of the result obtained in the cursor.
- Liberation of resources (this one is optional, although it is advisable).
- Closing of the connection with the agent.

To realize you are and many other more things we have the following functions:

Function Description
mysql_connect ("host", "user", "password") It establishes the connection with the servant. There receives the host and the user and password with the one that must tune in.
mysql_select_db ("database", connection) It selects the database on which it goes to work
mysql_query (consultation, connection) He executes the consultation SQL indicated like the first parameter.
mysql_num_fields (cursor) He returns the number of attributes that appear in the cursor that passes to him like parameter and in the one that stores the result of the consultation
mysql_fetch_row (cursor) It advances to the following position of the line in cursor. He returns an array that each of the values contains in his cells of the attributes of the line.
mysql_free_result (cursor) It liberates the resources associated with the cursor.
mysql_close (connection) It closes the connection established with mysql_connect.

One of the advantages that provides the highest integration that PHP and MYSQL have is the existence of functions that allow to the programmer to gain access to the different structures that agree the database. Some of the functions are:

Function Description
mysql_list_dbs (connection) He returns in a cursor the names of the available databases in the servant to whom it has got connected with mysql_connect
mysql_list_tables (base_datos, connection) He returns in a cursor the names of the available stage in the database.
mysql_tablename (cursor, numero_fila) He returns the name of the table or database in which the stated cursor is
mysql_field_name (cursor, numero_col) He returns the name of the field which index passes like the second parameter
mysql_field_type (cursor, numero_Col) He returns the type of the field which index passes like the second parameter
mysql_field_len (cursor, numero_col) He returns the length of the field which index passes like the second parameter
mysql_field_flags (cursor, numero_col) He returns a series of indicative corresponding to characteristics of the attribute which index passes like the second parameter
mysql_affected_rows (connection) He returns the number of lines affected by an update or erasure
mysql_change_user (user, password) It changes user
mysql_create_db (basedatos) Believe a database with the name spent by parameter
mysql_drop_db (basedatos) It eliminates the database spent by parameter
mysql_insert_id (cursor) He returns the value generated for an AUTOINCREMENT

Previous chapter:
The language SQL and PHP

Following chapter:
Meetings



 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

buy-usedcars.co.uk , Incentive Travel Poland , Alltel prepaid phone , Kiteboards , SEO , kasa fiskalna , plastics