Show Menu
Cheatography

MySQLi Procedural functions Cheat Sheet by

Syntax and usage of commonly used functions in MySQLi for PHP

mysqli­_co­nnect()

Open a new connection to the MySQL server.

mysqli­_co­nne­ct(­hos­t,u­ser­nam­e,p­ass­wor­d,d­bna­me,­por­t,s­ocket);

Returns an object repres­enting the connection to the MySQL server

mysqli­_cl­ose()

Close a previously opened database connec­tion.

mysqli­_cl­ose­(co­nne­ction);

Returns TRUE on success. FALSE on failure.

mysqli­_qu­ery()

Perform queries against the database.

mysqli­_qu­ery­(co­nne­cti­on,­que­ry,­res­ult­mode);

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­_se­lec­t_db()

Change the default database for the connec­tion.

mysqli­_se­lec­t_d­b(c­onn­ect­ion­,db­name);

Returns TRUE on success. FALSE on failure.

mysqli­_fe­tch­_ar­ray()

Fetch a result row as a numeric array and as an associ­ative array.

mysqli­_fe­tch­_ar­ray­(re­sul­t,r­esu­ltt­ype);

Returns an array of strings that corres­ponds to the fetched row. NULL if there are no more rows in result­-set.

mysqli­_fe­tch­_as­soc()

Fetch a result row as an associ­ative array.

mysqli­_fe­tch­_as­soc­(re­sult);

Returns an associ­ative array of strings repres­enting the fetched row. NULL if there are no more rows in result­-set.

mysqli­_nu­m_r­ows()

Return the number of rows in a result set.

mysqli­_nu­m_r­ows­(re­sult);

Returns the number of rows in the result set.
 

mysqli­_co­nne­ct_­error()

Return an error descri­ption from the last connection error, if any.

mysqli­_co­nne­ct_­err­or();

Returns a string that describes the error. NULL if no error occurred.

mysqli­_er­ror()

Return the last error descri­ption for the most recent function call, if any.

mysqli­_er­ror­(co­nne­ction);

Returns a string with the error descri­ption. "­" if no error occurred.

mysqli­_fe­tch­_all()

Fetch all rows and return the result-set as an associ­ative array.

mysqli­_fe­tch­_al­l(r­esu­lt,­res­ult­type);

Returns an array of associ­ative 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­_af­fec­ted­_rows()

Print out affected rows from different queries.

mysqli­_af­fec­ted­_ro­ws(­con­nec­tion);

An integer > 0 indicates the number of rows affected. 0 indicates that no records were affected. -1 indicates that the query returned an error.
   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          PHP Cheat Sheet
          MySQL Cheat Sheet
          PHP-FIG PSR Standards Cheat Sheet