This document discusses creating a database and table in MySQL, inserting records into the table using PHP functions like mysqli_connect() and mysqli_query(), retrieving records from the table with mysqli_num_rows() and mysqli_fetch_array(), and updating and deleting records. It provides examples of SQL commands to create a database and table, and examples of PHP functions to connect to the database, perform queries, retrieve results, and close connections.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
66 views
PHP & Mysql
This document discusses creating a database and table in MySQL, inserting records into the table using PHP functions like mysqli_connect() and mysqli_query(), retrieving records from the table with mysqli_num_rows() and mysqli_fetch_array(), and updating and deleting records. It provides examples of SQL commands to create a database and table, and examples of PHP functions to connect to the database, perform queries, retrieve results, and close connections.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11
PHP & MYSQL
Database Creation and Table
Creation in MySQL mysql> create database demo; Query OK, 1 row affected (0.02 sec)
mysql> use demo; Database changed
mysql> create table persons(person_id int(4) not null primary key
auto_increment,first_name char(30) not null,last_name char(30) not null,email_address varchar(50)); Query OK, 0 rows affected (0.24 sec) Insertion Output: Records added successfully mysqli_connect() function opens a new connection to the MySQL server. mysqli_connect(host,username,password,dbname,port,socket);
die() function prints a message and exits the current script.
mysqli_connect_error() function returns the error description
from the last connection error mysqli_query() function performs a query against the database. mysqli_query(connection,query,resultmode);
mysqli_close() function closes a previously opened database
connection. Insertion with forms Insertion with forms Output: Records added successfully Retrieving the Records mysqli_num_rows() function returns the number of rows in a result set. mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both. mysqli_fetch_array(result,resulttype); mysqli_free_result() function frees the memory associated with the result. mysqli_error() function returns the last error description Updating Records Deletion of Records