ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:mysql_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
v5:userguide:mysql_tutorial [2016/02/18 23:06] – escape -> to avoid entities conversion + formatting dregadv5:userguide:mysql_tutorial [2016/02/27 18:44] – [Select Limit and Top Support] mnewnham
Line 176: Line 176:
 When you move to another database, your insert might no longer work. When you move to another database, your insert might no longer work.
  
-The first problem is that each database has a different default date format. MySQL expects YYYY-MM-DD format, while other databases have different defaults. ADOdb has a function called [[v5:reference:dbdate]] that addresses this issue by converting converting the date to the correct format.+The first problem is that each database has a different default date format. MySQL expects YYYY-MM-DD format, while other databases have different defaults. ADOdb has a function called [[v5:reference:connection:dbdate|dbDate()]] that addresses this issue by converting converting the date to the correct format.
  
-The next problem is that the //don't// in the Note needs to be quoted. In MySQL, we use ''don\'t'' but in some other databases (Sybase, Access, Microsoft SQL Server) we use ''don''t''. The [[v5:reference:qstr]] function addresses this issue.+The next problem is that the //don't// in the Note needs to be quoted. In MySQL, we use ''don\'t'' but in some other databases (Sybase, Access, Microsoft SQL Server) we use ''don%%''%%t''. The [[v5:reference:connection:qStr()]] function addresses this issue.
  
 So how do we use the functions? Like this: So how do we use the functions? Like this:
Line 191: Line 191:
 </code> </code>
  
-ADOdb also supports [[v5:reference:affected_rows|''$connection->affected_rows()'']] (returns the number of rows affected by last update or delete) and [[v5:reference:insert_id|''$recordset->insert_id()'']] (returns last autoincrement number generated by an insert statement). Be forewarned that not all databases support the two functions.+ADOdb also supports ''[[v5:reference:connection:affected_rows|$connection->affected_rows()]]'' (returns the number of rows affected by last update or delete) and ''[[v5:reference:connection:insert_id|$recordset->insert_id()]]'' (returns last autoincrement number generated by an insert statement). Be forewarned that **not all databases support the two functions**.
  
-===== MetaTypes =====+==== MetaTypes ====
  
 You can find out more information about each of the fields (I use the words fields and columns interchangeably) you are selecting by calling the recordset method ''FetchField($fieldoffset)''. This will return an object with 3 properties: //name//, //type// and //max_length//. You can find out more information about each of the fields (I use the words fields and columns interchangeably) you are selecting by calling the recordset method ''FetchField($fieldoffset)''. This will return an object with 3 properties: //name//, //type// and //max_length//.
Line 203: Line 203:
 </code> </code>
  
-Then ''$f0->name'' will hold 'adata', ''$f0->type'' will be set to 'date'. If the //max_length// is unknown, it will be set to -1.+Then ''$f0%%->%%name'' will hold 'adata', ''$f0%%->%%type'' will be set to 'date'. If the //max_length// is unknown, it will be set to -1.
  
 One problem with handling different databases is that each database often calls the same type by a different name. For example a timestamp type is called //datetime// in one database and //time// in another. So ADOdb has a special ''MetaType($type, $max_length)'' function that standardises the types to the following: One problem with handling different databases is that each database often calls the same type by a different name. For example a timestamp type is called //datetime// in one database and //time// in another. So ADOdb has a special ''MetaType($type, $max_length)'' function that standardises the types to the following:
Line 226: Line 226:
 </code> </code>
  
-===== Select Limit and Top Support =====+==== Select Limit and Top Support ====
  
-ADOdb has a function called [[v5:reference:selectlimit|''$connection->SelectLimit($sql,$nrows,$offset)'']] that allows you to retrieve a subset of the recordset. This will take advantage of native ''SELECT TOP'' on Microsoft products and ''SELECT ... LIMIT'' with PostgreSQL and MySQL, and emulated if the database does not support it.+ADOdb has a function called ''[[v5:reference:connection:selectlimit|$connection->SelectLimit($sql,$nrows,$offset)]]'' that allows you to retrieve a subset of the recordset. This will take advantage of native ''SELECT TOP'' on Microsoft products and ''SELECT ... LIMIT'' with PostgreSQL and MySQL, and emulated if the database does not support it.
  
-===== Caching Support =====+==== Caching Support ====
  
 ADOdb allows you to cache recordsets in your file system, and only requery the database server after a certain timeout period with  ADOdb allows you to cache recordsets in your file system, and only requery the database server after a certain timeout period with 
Line 237: Line 237:
   * ''$connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset)''.   * ''$connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset)''.
  
-===== Session Handler Support =====+==== Session Handler Support ====
  
 ADOdb also supports session handlers. You can store your session variables in a database for true scalability using ADOdb. For further information, see the section on [[v5:session:session_index|Sessions]]. ADOdb also supports session handlers. You can store your session variables in a database for true scalability using ADOdb. For further information, see the section on [[v5:session:session_index|Sessions]].
v5/userguide/mysql_tutorial.txt · Last modified: 2018/06/27 16:09 by dregad