Download - PHP and database functionality
![Page 1: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/1.jpg)
PHP, PHP FRAMEWORKS AND DATABASE
Sayed AhmedComputer Engineering, BUET, BangladeshMSC, Computer Science, U of Manitoba, Canada
http://www.JustEtc.nethttp://[email protected]
![Page 2: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/2.jpg)
TOPICS Connection strategies Configuration for connection in
different frameworks PHP and DB2, MSSQL Server Common database oriented operations Reference to DB oriented
functions/classes
![Page 3: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/3.jpg)
CONNECTION mysql_connect mysqli_connect PDO
PDO_ODBC Connection from Frameworks
Code Igniter – configure for db connection CakePHP - configure for db connection Zend - configure for db connection
![Page 4: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/4.jpg)
PDO VS MYSQLI Overall, PDO is a better choice than
mysqli However, if performance is the only
issue that you care, and mysql will be the backend database all the
time, you can use mysqli
Reference: http://net.tutsplus.com/tutorials/php/pdo-v
s-mysqli-which-should-you-use/
![Page 5: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/5.jpg)
MYSQL_CONNECT mysql_connect
Opens a connection to a MySQL Server Deprecated as of PHP 5.5.0, and will be removed in the
future. Instead use MySQLi or PDO_MySQL
mysql_connect examples
![Page 6: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/6.jpg)
MYSQL_CONNECT EXAMPLES USING PORTS
![Page 7: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/7.jpg)
MYSQL_CONNECT USING PATH TO SOCKET
![Page 8: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/8.jpg)
MYSQLI_CONNECT — ALIAS OF MYSQLI::__CONSTRUCT()
![Page 9: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/9.jpg)
MYSQLI_CONNECT
![Page 10: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/10.jpg)
MYSQLI_CONNECT (OBJECT EXAMPLE)
![Page 11: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/11.jpg)
OBJECT ORIENTED STYLE CONNECTION WITH MYSQLI
![Page 12: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/12.jpg)
DATABASE CONNECTION WITH PDO
![Page 13: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/13.jpg)
PDO CONNECTION WHEN PARAMETERS IN A FILE
![Page 14: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/14.jpg)
PDO USING PHP.INI CONFIGURATIONS
![Page 15: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/15.jpg)
CODE IGNITER DATABASE CONFIGURATION application/config/database.php
$db['default']['hostname'] = "localhost";$db['default']['username'] = "root";$db['default']['password'] = "";$db['default']['database'] = "database_name";$db['default']['dbdriver'] = "mysql";$db['default']['dbprefix'] = "";$db['default']['pconnect'] = TRUE;$db['default']['db_debug'] = FALSE;$db['default']['cache_on'] = FALSE;$db['default']['cachedir'] = "";$db['default']['char_set'] = "utf8";$db['default']['dbcollat'] = "utf8_general_ci";$db['default']['swap_pre'] = "";$db['default']['autoinit'] = TRUE;$db['default']['stricton'] = FALSE;
Reference: http://ellislab.com/codeigniter/user-guide/database/configuration.html
![Page 16: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/16.jpg)
CAKEPHP AND MYSQL A copy of CakePHP’s database
configuration file is found in /app/Config/database.php.default
Make a copy of this file in the same directory, but name it database.php
Change database.php as follows
![Page 17: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/17.jpg)
CAKEPHP AND MYSQL
![Page 18: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/18.jpg)
ZEND AND DATABASE CONFIGURATION Zend_Config_Ini enables developers to
store configuration data in a familiar INI format
![Page 19: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/19.jpg)
PDO AND PREPARED STATEMENTS
![Page 20: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/20.jpg)
PDO FETCH AND PREPARED STMT
![Page 21: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/21.jpg)
PDO AND STORED PROCEDURE (OUT PARAM)
![Page 22: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/22.jpg)
PDO STRD PROC WITH IN/OUT PARAMS
![Page 23: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/23.jpg)
MYSQLI AND STORED PROCEDURE
![Page 24: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/24.jpg)
MYSQLI FETCHING RESULTS FROM STORED PROCEDURES
![Page 25: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/25.jpg)
PHP FUNCTIONS FOR SQL SERVER
The name of the functions may closely resemble the functionality. # mssql_ bind
# mssql_ close # mssql_ connect# mssql_ data_ seek# mssql_ execute# mssql_ fetch_ array# mssql_ fetch_ assoc# mssql_ fetch_ batch# mssql_ fetch_ field# mssql_ fetch_ object# mssql_ fetch_ row# mssql_ field_ length# mssql_ field_ name# mssql_ field_ seek# mssql_ field_ type# mssql_ free_ result# mssql_ free_ statement
![Page 26: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/26.jpg)
PHP FUNCTIONS FOR SQL SERVER # mssql_ get_ last_ message
# mssql_ guid_ string# mssql_ init# mssql_ min_ error_ severity# mssql_ min_ message_ severity# mssql_ next_ result# mssql_ num_ fields# mssql_ num_ rows# mssql_ pconnect# mssql_ query# mssql_ result# mssql_ rows_ affected# mssql_ select_ db
![Page 27: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/27.jpg)
PHP AND IBM DB2 PHP has concepts like PDO and PDO_ODBC, and generic odbc
features that will allow you to connect to and work with DB-2 databases. Generic odbc is the general/procedural way to connect to. PDO and PDO_ODBC are object oriented ways. PDO works with native IBM drivers. PDO_ODBC uses odbc connections to the DB2. For PHP you need to install drivers to support DB2. I worked with PDO_ODBC to connect to DB-2 databases in IBM iSeries servers. You need to install odbc db2 drivers for iseries servers. Then in /etc/odbcinst.ini file you need to mention driver specifications and in /etc/odbc.ini, you need to mention the odbc dsn name, database name, and some other parameters to connect to the database. Though, you may also supply some parameters in the PDO_ODBC connect method.
![Page 28: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/28.jpg)
PHP AND SQL SERVER STORED PROCEDURE
![Page 29: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/29.jpg)
PHP AND SQL SERVER STORED PROCEDURE
![Page 30: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/30.jpg)
MYSQL RELATED FUNCTIONS
![Page 31: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/31.jpg)
MYSQL RELATED FUNCTIONS
![Page 32: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/32.jpg)
MYSQL RELATED FUNCTIONS
![Page 33: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/33.jpg)
MYSQLI — THE MYSQLI CLASS mysqli::$affected_rows — Gets the number of affected rows
in a previous MySQL operation mysqli::autocommit — Turns on or off auto-committing
database modifications mysqli::begin_transaction — Starts a transaction mysqli::change_user — Changes the user of the specified
database connection mysqli::character_set_name — Returns the default character
set for the database connection mysqli::$client_info — Get MySQL client info mysqli::$client_version — Returns the MySQL client version as
a stringmysqli::close — Closes a previously opened database connection
![Page 34: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/34.jpg)
MYSQLI — THE MYSQLI CLASS mysqli::commit — Commits the current transaction mysqli::$connect_errno — Returns the error code from
last connect call mysqli::$connect_error — Returns a string description of
the last connect error mysqli::__construct — Open a new connection to the
MySQL server mysqli::debug — Performs debugging operations mysqli::dump_debug_info — Dump debugging
information into the log mysqli::$errno — Returns the error code for the most
recent function call
![Page 35: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/35.jpg)
MYSQLI — THE MYSQLI CLASS mysqli::$error_list — Returns a list of errors from the last command executed mysqli::$error — Returns a string description of the last error mysqli::$field_count — Returns the number of columns for the most recent
query mysqli::get_charset — Returns a character set objectmysqli::get_client_info —
Get MySQL client info mysqli_get_client_stats — Returns client per-process statistics mysqli_get_client_version — Returns the MySQL client version as an integer mysqli::get_connection_stats — Returns statistics about the client connection mysqli::$host_info — Returns a string representing the type of connection
used mysqli::$protocol_version — Returns the version of the MySQL protocol used mysqli::$server_info — Returns the version of the MySQL server mysqli::$server_version — Returns the version of the MySQL server as an
integer mysqli::get_warnings — Get result of SHOW WARNINGS
![Page 36: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/36.jpg)
MYSQLI — THE MYSQLI CLASS mysqli::$info — Retrieves information about the most recently
executed querymysqli::init — Initializes MySQLi and returns a resource for use with mysqli_real_connect()mysqli::$insert_id — Returns the auto generated id used in the last querymysqli::kill — Asks the server to kill a MySQL threadmysqli::more_results — Check if there are any more query results from a multi querymysqli::multi_query — Performs a query on the databasemysqli::next_result — Prepare next result from multi_querymysqli::options — Set optionsmysqli::ping — Pings a server connection, or tries to reconnect if the connection has gone downmysqli::poll — Poll connectionsmysqli::prepare — Prepare an SQL statement for executionmysqli::query — Performs a query on the databasemysqli::real_connect — Opens a connection to a mysql servermysqli::real_escape_string — Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connectionmysqli::real_query — Execute an SQL query
![Page 37: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/37.jpg)
MYSQLI_STMT — THE MYSQLI_STMT CLASS mysqli_stmt::$affected_rows — Returns the total number of
rows changed, deleted, or inserted by the last executed statementmysqli_stmt::attr_get — Used to get the current value of a statement attributemysqli_stmt::attr_set — Used to modify the behavior of a prepared statementmysqli_stmt::bind_param — Binds variables to a prepared statement as parametersmysqli_stmt::bind_result — Binds variables to a prepared statement for result storagemysqli_stmt::close — Closes a prepared statementmysqli_stmt::data_seek — Seeks to an arbitrary row in statement result setmysqli_stmt::$errno — Returns the error code for the most recent statement callmysqli_stmt::$error_list — Returns a list of errors from the last statement executed
![Page 38: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/38.jpg)
MYSQLI_RESULT — THE MYSQLI_RESULT CLASS
mysqli_result::$current_field — Get current field offset of a result pointermysqli_result::data_seek — Adjusts the result pointer to an arbitrary row in the resultmysqli_result::fetch_all — Fetches all result rows as an associative array, a numeric array, or bothmysqli_result::fetch_array — Fetch a result row as an associative, a numeric array, or bothmysqli_result::fetch_assoc — Fetch a result row as an associative arraymysqli_result::fetch_field_direct — Fetch meta-data for a single fieldmysqli_result::fetch_field — Returns the next field in the result setmysqli_result::fetch_fields — Returns an array of objects representing the fields in a result setmysqli_result::fetch_object — Returns the current row of a result set as an objectmysqli_result::fetch_row — Get a result row as an enumerated array
![Page 39: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/39.jpg)
MYSQLI_DRIVER, MYSQLI_WARNING mysqli_driver — The mysqli_driver classmysqli_driver::
embedded_server_end — Stop embedded server mysqli_driver::embedded_server_start — Initialize and
start embedded server mysqli_driver::$report_mode — Enables or disables
internal report functions mysqli_warning — The mysqli_warning class
mysqli_warning::__construct — The __construct purpose mysqli_warning::next — The next purpose mysqli_sql_exception — The mysqli_sql_exception class
![Page 40: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/40.jpg)
PDO — THE PDO CLASS PDO::beginTransaction — Initiates a transactionPDO
::commit — Commits a transactionPDO::__construct — Creates a PDO instance representing a connection to a databasePDO::errorCode — Fetch the SQLSTATE associated with the last operation on the database handlePDO::errorInfo — Fetch extended error information associated with the last operation on the database handlePDO::exec — Execute an SQL statement and return the number of affected rowsPDO::getAttribute — Retrieve a database connection attribute
![Page 41: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/41.jpg)
PDOSTATEMENT — THE PDOSTATEMENT CLASS
PDOStatement::bindColumn — Bind a column to a PHP variablePDOStatement::bindParam — Binds a parameter to the specified variable namePDOStatement::bindValue — Binds a value to a parameterPDOStatement::closeCursor — Closes the cursor, enabling the statement to be executed again.PDOStatement::columnCount — Returns the number of columns in the result setPDOStatement::debugDumpParams — Dump an SQL prepared commandPDOStatement::errorCode — Fetch the SQLSTATE associated with the last operation on the statement handlePDOStatement::errorInfo — Fetch extended error information associated with the last operation on the statement handle
![Page 42: PHP and database functionality](https://reader035.vdocuments.site/reader035/viewer/2022070511/58a0295d1a28ab4e768b5f15/html5/thumbnails/42.jpg)
PDOEXCEPTION, MISC PDOException — The PDOException
class PDO DriversCUBRID (PDO) — CUBRID
Functions (PDO_CUBRID) MS SQL Server (PDO) — Microsoft SQL
Server and Sybase Functions (PDO_DBLIB)
Firebird/Interbase (PDO) — Firebird/Interbase Functions (PDO_FIREBIRD)
IBM (PDO) — IBM Functions (PDO_IBM)