SlideShare uma empresa Scribd logo
1 de 42
PHP, PHP FRAMEWORKS AND DATABASE
Sayed Ahmed
Computer Engineering, BUET, Bangladesh
MSC, Computer Science, U of Manitoba, Canada
http://www.JustEtc.net
http://sayed.justetc.net
sayed@justetc.net
TOPICS
 Connection strategies
 Configuration for connection in different
frameworks
 PHP and DB2, MSSQL Server
 Common database oriented operations
 Reference to DB oriented functions/classes
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
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-vs-
mysqli-which-should-you-use/
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
MYSQL_CONNECT EXAMPLES USING PORTS
MYSQL_CONNECT USING PATH TO
SOCKET
MYSQLI_CONNECT — ALIAS OF MYSQLI::__CONSTRUCT()
MYSQLI_CONNECT
MYSQLI_CONNECT (OBJECT EXAMPLE)
OBJECT ORIENTED STYLE CONNECTION WITH MYSQLI
DATABASE CONNECTION WITH PDO
PDO CONNECTION WHEN PARAMETERS IN A FILE
PDO USING PHP.INI CONFIGURATIONS
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
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
CAKEPHP AND MYSQL
ZEND AND DATABASE CONFIGURATION
 Zend_Config_Ini enables developers to store
configuration data in a familiar INI format
PDO AND PREPARED STATEMENTS
PDO FETCH AND PREPARED STMT
PDO AND STORED PROCEDURE (OUT
PARAM)
PDO STRD PROC WITH IN/OUT PARAMS
MYSQLI AND STORED PROCEDURE
MYSQLI FETCHING RESULTS FROM STORED PROCEDURES
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
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
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.
PHP AND SQL SERVER STORED PROCEDURE
PHP AND SQL SERVER STORED PROCEDURE
MYSQL RELATED FUNCTIONS
MYSQL RELATED FUNCTIONS
MYSQL RELATED FUNCTIONS
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
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
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
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
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
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
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
classmysqli_warning::__construct — The __construct
purpose
 mysqli_warning::next — The next purpose
 mysqli_sql_exception — The mysqli_sql_exception
class
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
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
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)

Mais conteúdo relacionado

Mais procurados

Mais procurados (17)

Php mysql connectivity
Php mysql connectivityPhp mysql connectivity
Php mysql connectivity
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objects
 
MySQL
MySQLMySQL
MySQL
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
Mysql
MysqlMysql
Mysql
 
lab56_db
lab56_dblab56_db
lab56_db
 
Sqlite perl
Sqlite perlSqlite perl
Sqlite perl
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
veracruz
veracruzveracruz
veracruz
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
9780538745840 ppt ch06
9780538745840 ppt ch069780538745840 ppt ch06
9780538745840 ppt ch06
 
Stored Procedure
Stored ProcedureStored Procedure
Stored Procedure
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
 

Destaque

[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...
[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...
[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...K data
 
跨平台開發從測試到架構
跨平台開發從測試到架構跨平台開發從測試到架構
跨平台開發從測試到架構Chris Jeng
 
[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료
[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료
[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료K data
 
2016 네이버sw기술소개
2016 네이버sw기술소개2016 네이버sw기술소개
2016 네이버sw기술소개NAVER Engineering
 
OLE-DB vs ODBC
OLE-DB vs ODBCOLE-DB vs ODBC
OLE-DB vs ODBCTom
 

Destaque (7)

Trees in RDBs
Trees in RDBsTrees in RDBs
Trees in RDBs
 
[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...
[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...
[2016 데이터 그랜드 컨퍼런스] 5 1(보안,품질). 웨어밸리 data security challenges and its solutio...
 
跨平台開發從測試到架構
跨平台開發從測試到架構跨平台開發從測試到架構
跨平台開發從測試到架構
 
[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료
[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료
[2016 데이터 그랜드 컨퍼런스] 6 2(전략,솔루션). 큐브리드 오픈소스 dbms의 클라우드 구축 사례-발표자료
 
2016 네이버sw기술소개
2016 네이버sw기술소개2016 네이버sw기술소개
2016 네이버sw기술소개
 
Prashanthi
PrashanthiPrashanthi
Prashanthi
 
OLE-DB vs ODBC
OLE-DB vs ODBCOLE-DB vs ODBC
OLE-DB vs ODBC
 

Semelhante a PHP Database Connection and Operations

20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnddo_aki
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Developmentw3ondemand
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For BeginnersPriti Solanki
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Chris Barber
 
Mysql connection
Mysql connectionMysql connection
Mysql connectionbeben benzy
 
PHP - PDO Objects
PHP - PDO ObjectsPHP - PDO Objects
PHP - PDO ObjectsAJINKYA N
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxmoirarandell
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13Hassen Poreya
 
Collection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxCollection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxKingKhaliilHayat
 
Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26SynapseindiaComplaints
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5John Coggeshall
 

Semelhante a PHP Database Connection and Operations (20)

20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnd
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
Mysql connection
Mysql connectionMysql connection
Mysql connection
 
Db function
Db functionDb function
Db function
 
Php verses my sql
Php verses my sqlPhp verses my sql
Php verses my sql
 
PHP - PDO Objects
PHP - PDO ObjectsPHP - PDO Objects
PHP - PDO Objects
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
Collection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxCollection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docx
 
Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHPPHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHP
 

Mais de Sayed Ahmed

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsSayed Ahmed
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commandsSayed Ahmed
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic frameworkSayed Ahmed
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSayed Ahmed
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction toSayed Ahmed
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overviewSayed Ahmed
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend frameworkSayed Ahmed
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3Sayed Ahmed
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2Sayed Ahmed
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_htmlSayed Ahmed
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcutsSayed Ahmed
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfonySayed Ahmed
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayedSayed Ahmed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_designSayed Ahmed
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrativeSayed Ahmed
 

Mais de Sayed Ahmed (20)

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
 
Virtualization
VirtualizationVirtualization
Virtualization
 
User interfaces
User interfacesUser interfaces
User interfaces
 
Unreal
UnrealUnreal
Unreal
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
 

Último

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 

Último (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 

PHP Database Connection and Operations

  • 1. PHP, PHP FRAMEWORKS AND DATABASE Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada http://www.JustEtc.net http://sayed.justetc.net sayed@justetc.net
  • 2. TOPICS  Connection strategies  Configuration for connection in different frameworks  PHP and DB2, MSSQL Server  Common database oriented operations  Reference to DB oriented functions/classes
  • 3. 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
  • 4. 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-vs- mysqli-which-should-you-use/
  • 5. 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
  • 8. MYSQLI_CONNECT — ALIAS OF MYSQLI::__CONSTRUCT()
  • 11. OBJECT ORIENTED STYLE CONNECTION WITH MYSQLI
  • 13. PDO CONNECTION WHEN PARAMETERS IN A FILE
  • 14. PDO USING PHP.INI CONFIGURATIONS
  • 15. 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
  • 16. 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
  • 18. ZEND AND DATABASE CONFIGURATION  Zend_Config_Ini enables developers to store configuration data in a familiar INI format
  • 19. PDO AND PREPARED STATEMENTS
  • 20. PDO FETCH AND PREPARED STMT
  • 21. PDO AND STORED PROCEDURE (OUT PARAM)
  • 22. PDO STRD PROC WITH IN/OUT PARAMS
  • 23. MYSQLI AND STORED PROCEDURE
  • 24. MYSQLI FETCHING RESULTS FROM STORED PROCEDURES
  • 25. 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
  • 26. 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
  • 27. 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.
  • 28. PHP AND SQL SERVER STORED PROCEDURE
  • 29. PHP AND SQL SERVER STORED PROCEDURE
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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 classmysqli_warning::__construct — The __construct purpose  mysqli_warning::next — The next purpose  mysqli_sql_exception — The mysqli_sql_exception class
  • 40. 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
  • 41. 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
  • 42. 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)