Cheatography
https://cheatography.com
Syntax and usage of commonly used functions in MySQLi for PHP
mysqli_connect()
Open a new connection to the MySQL server.
mysqli_connect(host,username,password,dbname,port,socket);
Returns an object representing the connection to the MySQL server |
mysqli_close()
Close a previously opened database connection.
mysqli_close(connection);
Returns TRUE on success. FALSE on failure. |
mysqli_query()
Perform queries against the database.
mysqli_query(connection,query,resultmode);
For successful SELECT, SHOW, DESCRIBE, or EXPLAIN queries it will return a mysqli_result object. For other successful queries it will return TRUE. FALSE on failure. |
mysqli_select_db()
Change the default database for the connection.
mysqli_select_db(connection,dbname);
Returns TRUE on success. FALSE on failure. |
mysqli_fetch_array()
Fetch a result row as a numeric array and as an associative array.
mysqli_fetch_array(result,resulttype);
Returns an array of strings that corresponds to the fetched row. NULL if there are no more rows in result-set. |
mysqli_fetch_assoc()
Fetch a result row as an associative array.
mysqli_fetch_assoc(result);
Returns an associative array of strings representing the fetched row. NULL if there are no more rows in result-set. |
mysqli_num_rows()
Return the number of rows in a result set.
mysqli_num_rows(result);
Returns the number of rows in the result set. |
|
|
mysqli_connect_error()
Return an error description from the last connection error, if any.
mysqli_connect_error();
Returns a string that describes the error. NULL if no error occurred. |
mysqli_error()
Return the last error description for the most recent function call, if any.
mysqli_error(connection);
Returns a string with the error description. "" if no error occurred. |
mysqli_fetch_all()
Fetch all rows and return the result-set as an associative array.
mysqli_fetch_all(result,resulttype);
Returns an array of associative or numeric arrays holding the result rows. |
Result type: Optional. Specifies what type of array that should be produced. Can be one of the following values:
MYSQLI_ASSOC
MYSQLI_NUM
MYSQLI_BOTH
mysqli_affected_rows()
Print out affected rows from different queries.
mysqli_affected_rows(connection);
An integer > 0 indicates the number of rows affected. 0 indicates that no records were affected. -1 indicates that the query returned an error. |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets