<doc>
	<legacy_id>2188</legacy_id>
	<name>revOpenDatabase</name>
	<type>function</type>

	<syntax>
		<example>revOpenDatabase("mysql",<i>host</i>[:<i>port</i>], <i>databaseName</i>, [<i>userName</i>],[<i>password</i>],[useSSL], [socket], [timeout], [autoReconnect])</example>
		<example>revOpenDatabase("odbc",<i>host</i>[:<i>port</i>], <i>databaseName</i>, [<i>userName</i>],[<i>password</i>],[<i>cursorType</i>])</example>
		<example>revOpenDatabase("sqlite",<i>filepath,</i>[<i>sqliteOptions</i>])</example>
		<example>revOpenDatabase("postgresql",<i>host</i>[:<i>port</i>], <i>databaseName</i>, [<i>userName</i>],[<i>password</i>])</example>
		<example>revOpenDatabase("oracle",<i>host</i>[:<i>port</i>], <i>databaseName</i>, [<i>userName</i>],[<i>password</i>])</example>
	</syntax>

	<synonyms>
		<synonym>revdb_connect</synonym>
	</synonyms>

	<summary>Connects to a MySQL, SQLite, PostgreSQL, ODBC or Oracle database.</summary>

	<examples>
<example>get revOpenDatabase("mysql", "www.example.com", "RatesDB", myUsr, myPass)</example>
<example>get revOpenDatabase("odbc", "BizFile", , "jenkins" ,the dbPassword of me, "emulated static")</example>
<example><p>put revOpenDatabase("sqlite", "mydb.sqlite") -- open with legacy binary mode and loadable extensions disabled</p><p>put revOpenDatabase("sqlite", "mydb.sqlite", "binary") -- open the connection in the 'new' binary mode</p><p>put revOpenDatabase("sqlite", "mydb.sqlite", "extensions") -- enable loadable extensions for this connection</p><p>put revOpenDatabase("sqlite", "mydb.sqlite", "binary,extensions") -- enable both 'new' binary mode and loadable extensions</p></example>
<example>get revOpenDatabase("mysql", "localhost", "dbName", myUsr, myPass, false, "/var/mysql.sock", 1, true)</example>
	</examples>

	<history>
		<introduced version="1.1">Added.</introduced>
		<deprecated version=""></deprecated>
		<removed version=""></removed>
		<changed version="2.9">2.9</changed>
<changed version="4.6.4">Updated</changed>
		<experimental version=""></experimental>
		<nonexperimental version=""></nonexperimental>
	</history>

	<objects>
	</objects>

	<platforms>
		<mac/>
		<windows/>
		<linux/>
		<ios/>
		<android/>
	</platforms>

	<classes>
		<desktop/>
		<server/>
		<web/>
		<mobile/>
	</classes>

	<security>
		<disk/>
		<network/>
	</security>


	<classification>
		<category>Database Operations</category>
		<category>Standalone Applications</category>
	</classification>

	<references>
		<function tag="revLicenseType">revLicenseType Function</function>
		<function tag="revDatabaseID">revDatabaseID Function</function>
		<function tag="revDatabaseConnectResult">revDatabaseConnectResult Function</function>
		<function tag="revDatabaseTableNames">revDatabaseTableNames Function</function>
		<function tag="revQueryIsAtStart">revQueryIsAtStart Function</function>
		<command tag="revExecuteSQL">revExecuteSQL Command</command>
		<command tag="revSetDatabaseDriverPath">revSetDatabaseDriverPath Command</command>
	</references>

	<description>
	<overview>Use the <b>revOpenDatabase</b> function to start working with a database.</overview>

		<parameters>
  <parameter>
    <name>databaseType</name>
    <description>A string specifying the database type to use. One of the following:</description>
    <options title="">
      <option>
        <item>mysql</item>
        <description/>
      </option>
      <option>
        <item>oracle</item>
        <description/>
      </option>
      <option>
        <item>odbc</item>
        <description/>
      </option>
      <option>
        <item>postgresql</item>
        <description/>
      </option>
      <option>
        <item>valentina</item>
        <description/>
      </option>
      <option>
        <item>sqlite</item>
        <description/>
      </option>
    </options>
  </parameter>
  <parameter>
    <name>host</name>
    <description>A string specifying the IP address or domain name of the system hosting the database. For SQLite databases, the host should be the full path to the database file.</description>
  </parameter>
  <parameter>
    <name>filename</name>
    <description>(SQLite Only) A string specifying the path to the SQLite database.</description>
  </parameter>
  <parameter>
    <name>port</name>
    <description>A number specifying the port number you want to connect to, and is used only for MySQL and PostgreSQL databases. If no port is specified, MySQL database connections use port 3306 and PostgreSQL database connections use port 5432.</description>
  </parameter>
  <parameter>
    <name>databaseName</name>
    <description>A string specifying the the name of the database to connect to. For SQLite databases, the database name should be left empty.</description>
  </parameter>
  <parameter>
    <name>userName</name>
    <description>A string specifying your authorized user name for the database (Some databases do not require a user name).</description>
  </parameter>
  <parameter>
    <name>password</name>
    <description>A string specifying the authentication password for the userName (Some databases do not require a password).</description>
  </parameter>
  <parameter>
    <name>useSSL</name>
    <description>(MySQL Only) A boolean specifying whether to use SSL to secure the socket connection when connecting to a MySQL database. If you use this feature in a standalone application, remember to select 'SSL  Encryption' from among the available 'script libraries' in the standalone application settings panel. </description>
  </parameter>
  <parameter>
    <name>socket</name>
    <description>(MySQL Only) A string specifying the socket or named pipe the driver should use to connect with.  If empty, the default for the host will be used. </description>
  </parameter>
  <parameter>
    <name>timeout</name>
    <description>(MySQL Only)  A number specifying the database read/write timeout in whole seconds.  Defaults to 20 seconds if empty or not a positive integer. If 0, the connection never times out.</description>
  </parameter>
  <parameter>
    <name>autoReconnect</name>
    <description>(MySQL Only) A boolean specifying if the driver should attempt to automatically reconnect to the database when the connection is lost. A reconnection attempt will be made the next time a command is executed.</description>
  </parameter>
  <parameter>
    <name>cursorType</name>
    <description>(ODBC Only) A string specifying the type of cursor to use.</description>
    <options title="">
      <option>
        <item>static</item>
        <description>This is a scrollable static cursor. Using this cursor it is possible to navigate backwards as well as forwards through record sets, and to move straight to the first or last record. Static cursors operate on an "offline" copy of the data, meaning that any changes to the data will not be detected by the cursor. Not all ODBC drivers support static cursors, for example FileMaker 6 does not.</description>
      </option>
      <option>
        <item>forward only</item>
        <description>This is a cursor that can be scrolled forwards only. All ODBC drivers must support this type of cursor. Forward only cursors are usually faster than scrollable static cursors, but using revMoveToPreviousRecord, revMoveToFirstRecord or revMoveToLastRecord will fail. Forward only is the default cursor type, and is what was used in LiveCode 2.8.1 and earlier.</description>
      </option>
      <option>
        <item>emulated static</item>
        <description>This cursor has the same behavior as a static cursor, except it allows ODBC to emulate the cursor's behavior if the driver does not support it. ODBC can typically emulate static cursor behavior on Windows systems only.</description>
      </option>
    </options>
  </parameter>
<parameter>
    <name>sqliteOptions</name>
    <description>A comma delimited list contain one or me of the following (Note that the order of the items in the options parameter is not important):</description>
    <options title="">
      <option>
        <item>binary</item>
        <description>Places binary data into the database verbatim (without LiveCode encoding).</description>
      </option>
      <option>
        <item>extensions</item>
        <description>Enable loadable extensions for the connection.</description>
      </option>
    </options>
  </parameter>		</parameters>

	<value>The <b>revOpenDatabase</b> function returns a database ID which can be used to refer to the database in other Database library commands and functions. The database ID is always an integer.<p></p><p>If the database is not successfully opened, the <b>revOpenDatabase</b> function returns an error message. The error message is never an integer, so you can check whether the connection was successful by checking whether the return value is an integer or not.</p></value>
	<comments><note> To use a DSN to identify an ODBC database, use the DSN as the host, and leave the databaseName parameter empty.<p></note><p></p><important> The revOpenDatabase function is part of the Database library. To ensure that the function works in a standalone application, you must include this custom library when you create your standalone. In the Inclusions section of the General screen of the Standalone Application Settings window, make sure the Database Support checkbox is checked and the database drivers you are using are selected in the list of database drivers.</important><p></p><p></p><change><p><i><b>LiveCode 6.6</b></i></change><p></p><p>The version of SQLite has been updated to 3.8.2.</p><p></p><p>The SQLite RTREE module is now available.</p><p></p><p>SQLite loadable extensions are now supported. To utilize loadable extensions, the 'extensions' option must be passed to the revOpenDatabase() call when creating the database connection.</p><p></p><p>Binary data can now be placed into SQLite databases verbatim (without the encoding that used to occur) - this means databases can be made to contain binary data which is compatible with other applications. To utilize this functionality, the 'binary' option must be passed to the revOpenDatabase() call when creating the database connection.</p><p></p><p>The SQLite revOpenDatabase() call no longer requires 5 arguments and only requires a minimum of 2.</p></comments>
	</description>
</doc>