For the beginning we create a database and the table. We enter in MySQL, and we execute commands:
> CREATE DATABASE products;
> CREATE TABLE clients (name VARCHAR (25), email VARCHAR (25), choice VARCHAR (8));
Following functions will be necessary for dialogue with MySQL from PHP.
int mysql_connect (string hostname, string username, string password);
To create connection with MySQL.
Parameters:
- Hostname - a name of a host on which there is a database.
- Username - a name of the user.
- Password - the password of the user.
Function returns parameter of type int which is more 0 if connection has passed successfully, and is equal 0 otherwise.
int mysql_select_db (string database_name, int link_identifier);
To choose a database for work.
Parameters:
- Database_name - a name of a database.
- link_identifier - ID connections which is received in function mysql_connect. (parameter unessential if it is not underlined it is used ID from last call mysql_connect)
Function returns value true or false
int mysql_query (string query, int link_identifier);
Function carries out inquiry to a database.
Parameters:
- Query - a line containing inquiry
- link_identifier - ID connections which is received in function mysql_connect. (parameter unessential if it is not underlined it is used ID from last call mysql_connect).
Function returns ID result or 0 if there was a mistake.
int mysql_close (int link_identifier);
Function closes connection with MySQL.
Parameters:
link_identifier - ID connections which is received in function mysql_connect. (parameter unessential if it is not
underlined it is used ID from last call mysql_connect).
Function returns value true or false
int mysql_num_rows (int result);
Function returns quantity of lines as a result of inquiry.
The parameter result - contains ID result of inquiry.
int mysql_result (int result, int i, column);
Function returns value of a field in a column column and in line i.
Using the listed base functions it is possible to work easily with database MySQL in PHP.
|