Connecting PHP and MYSQL - Formula Sheet
Core Functions and Parameters
Below is a quick reference table of key PHP database connection functions, parameter structures, and their return behaviors.
| Function Name | Syntax and Parameters | Return Value | Description |
|---|---|---|---|
| mysqli_connect | mysqli_connect(host, username, password, dbname) | Connection object (or false on failure) | Establishes a connection to the MySQL server and selects the specified database. |
| mysqli_query | mysqli_query(connection_link, query_string) | Result object (for SELECT) or boolean (for INSERT/UPDATE/DELETE) | Sends an SQL query to the database server for execution. |
| mysqli_close | mysqli_close(connection_link) | Boolean (true on success, false on failure) | Closes an open connection link and releases system resources. |
| mysqli_connect_error | mysqli_connect_error() | String describing the error (or null) | Returns a textual explanation of the last connection failure. |
| mysqli_num_rows | mysqli_num_rows(result_object) | Integer (number of rows) | Retrieves the total number of records returned by a SELECT query. |
| mysqli_fetch_array | mysqli_fetch_array(result_object) | Array representing the row (or false if none) | Fetches the next row of data as an associative or numeric array. |
Key Configuration Rules
- Server Host: Typically 'localhost' when executing scripts on the same server where the MySQL database resides.
- Default Port: MySQL server usually listens on port 3306. This is handled internally unless specified otherwise in advanced parameters.
- PHP Version Minimum: PHP version 5.0.0 or higher is required to use the mysqli extensions natively.
More for this chapter
Book Back Questions10 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Applications
View all
1 Multimedia
2 An Introduction to Adobe PageMaker
3 Introduction to Database Management System
4 PHP: Hypertext Preprocessor
5 Functions and Arrays in PHP
6 Conditional Statements in PHP
7 Loops in PHP
8 Forms and Files
10 Introduction to Computer Networks
11 Network Examples and Protocols
12 Domain Name System (DNS)
13 Network Cabling
14 Open Source Concepts
15 E-Commerce
16 Electronic Payment Systems
17 E-Commerce Security Systems
18 Electronic Data Interchange- EDI