Difference between revisions of "RDO CONNECT()"

From Recital Documentation Wiki
Jump to: navigation, search
 
(13 intermediate revisions by one user not shown)
Line 1: Line 1:
{{YLM to do}}
+
==Purpose==
Numeric = rdo_connect(servertype as character, hostname as character, username as character, password as character, database as character)
+
Connect to a data source
  
  
Closes a connection
+
==Syntax==
rdo_close(connection as Numeric)
+
RDO_CONNECT(<expC1>, <expC2>, <expC3>, <expC4> [, <expC5>])
mysql_close(connection as Numeric)
+
  
The mysql_select_db() function sets the active database
+
MYSQL_CONNECT(<expC1>, <expC2>, <expC3>, <expC4> [, <expC5>])
Numeric = rdo_select_db(database as Character [, connection as Numeric] )
+
Numeric = mysql_select_db(database as Character [, connection as Numeric] )
+
  
The mysql_list_dbs() function finds the available databases for a given connection.
 
Object = rdo_list_dbs(connection as Numeric)
 
Object = mysql_list_dbs(connection as Numeric)
 
  
This function returns the number of affected rows on success, or -1 if the last operation failed
+
==See Also==
Numeric = rdo_affected_rows()
+
[[RDO_AFFECTED_ROWS()]], [[RDO_CLOSE()]], [[RDO_DATA_SEEK()]], [[RDO_ERRNO()]], [[RDO_ERROR()]], [[RDO_EXEC()]], [[RDO_FETCH_ARRAY()]], [[RDO_FETCH_ASSOC()]], [[RDO_FETCH_FIELD()]], [[RDO_FETCH_LENGTHS()]], [[RDO_FETCH_OBJECT()]], [[RDO_FETCH_ROW()]], [[RDO_FIELD_FLAGS()]], [[RDO_FIELD_LEN()]], [[RDO_FIELD_NAME()]], [[RDO_FIELD_SEEK()]], [[RDO_FIELD_TABLE()]], [[RDO_FIELD_TYPE()]], [[RDO_FREE_OBJECT()]], [[RDO_FREE_RESULT()]], [[RDO_GET_CLIENT_INFO()]], [[RDO_GET_HOST_INFO()]], [[RDO_INFO()]], [[RDO_LIST_DBS()]], [[RDO_NUM_FIELDS()]], [[RDO_NUM_ROWS()]], [[RDO_PING()]], [[RDO_QUERY()]], [[RDO_REAL_ESCAPE_STRING()]], [[RDO_RESULT()]], [[RDO_SELECT_DB()]], [[RDO_STAT()]], [[RDO_THREAD_ID()]], [[RDO_UNBUFFERED_QUERY()]]
Numeric = mysql_affected_rows()
+
  
Returns the error number of the last operation
 
Numeric = rdo_errno()
 
Numeric = mysql_errno()
 
  
Returns the error description of the last Recital operation
+
==Description==
Character = rdo_error()
+
The RDO_CONNECT() function is used to connect to a data source.  The numeric value returned should be saved to a variable to be used by other functions to reference the connection.  Connection references start from 0 and correspond to the [[SELECT()|cursor/workarea]] -1.  If RDO_CONNECT() returns -1, the connection failed.
Character = mysql_error()
+
  
Returns a row from a recordset as an associative array
 
Object = rdo_fetch_array(query as Character)
 
Object = rdo_fetch_assoc(query as Character)
 
Object = mysql_fetch_array(query as Character)
 
Object = mysql_fetch_assoc(query as Character)
 
  
This function returns a ResultSet Object for SELECT queries
+
{| class="wikitable"
Object = rdo_query(query as Character [, connection as Numeric] )
+
!Keywords||Description
Object = rdo_unbuffered_query(char query [, connection as Numeric] )
+
|-
Object = mysql_query(query as Character [, connection as Numeric] )
+
|<expC1>||Servertype: "recital", "oracle", "db2", "mysql" or "postgres"
Object = mysql_unbuffered_query(char query [, connection as Numeric] )
+
|-
TIP
+
|<expC2>||Hostname: IP address or character name
The mysql_query() function returns an associative array where each item in the array is an associative array containing the fields for each record returned from the query. Use the FOREACH statement to traverse this data.
+
|-
 +
|<expC3>||Username: account used to access the data source
 +
|-
 +
|<expC4>||Password: password for account above
 +
|-
 +
|<expC5>||Database: database to connect to
 +
|-
 +
|}
  
e.g.
 
  
connection = mysql_connect("localhost", myusername, mpassword)
+
==Example==
mysql_select_db("mydatabase")
+
<code lang="recital">
resultset = mysql_query("select * from customers", connection)
+
conn = rdo_connect("mysql","localhost", "user", "pass", "test")
foreach resultset as r
+
if conn > -1
     echo r["fieldname"]
+
    rdo_exec("create table mytable (phrase char(20))", conn)
endfor
+
     rdo_exec("insert into mytable values ('Hello world')")
This function executes non-SELECT statements
+
    echo rdo_affected_rows()
Numeric = rdo_exec(command as Character [, connection as Numeric] )
+
    rdo_close(conn)
Numeric = mysql_exec(command as Character [, connection as Numeric] )
+
endif
TIP
+
</code>
You can use the mysql_exec() function to create tables and insert data.
+
  
e.g.
 
  
mysql_exec("create table mytable (name char(10))", connection)
+
==Products==
mysql_exec("insert into mytable values ('Hello world')")
+
Recital, Recital Server
 
+
[[Category:Documentation]]
However, Recital is a database centric scripting language so you can just place the sql commands directly in your program code.
+
[[Category:Functions]]
 
+
[[Category:SQL]]
// open a new mysql connection
+
[[Category:Remote Data Connectivity]]
connection = mysql_connect("localhost", myusername, mypassword)
+
[[Category:Remote Data Connectivity Functions]]
 
+
// The mysql connection is selected after the mysql_connect() function returns
+
create table mytable (name char(10))
+
insert into mytable values ('Hello world')
+
 
+
// close the connection
+
mysql_close(connection)
+
The following functions returns the next row from a recordset as an Object
+
Object = rdo_fetch_object(resultset as Object)
+
Object = rdo_fetch_row(resultset as Object)
+
Object = mysql_fetch_object(resultset as Object)
+
Object = mysql_fetch_row(resultset as Object)
+
 
+
The mysql_num_rows() function returns the number of rows in a recordset
+
Numeric = rdo_num_rows(resultset as Object)
+
Numeric = mysql_num_rows(resultset as Object)
+
 
+
Returns the number of fields in a recordset
+
Numeric = rdo_num_fields(resultset as Object)
+
Numeric = mysql_num_fields(resultset as Object)
+
 
+
The mysql_data_seek() function moves the internal row pointer
+
Numeric = rdo_data_seek(Resultset as Object, Row as Numeric)
+
Numeric = mysql_data_seek(Resultset as Object, Row as Numeric)
+
 
+
The mysql_field_seek() function jumps to a specified field in a recordset
+
Numeric = rdo_field_seek(Resultset as Object, Column as Numeric)
+
Numeric = mysql_field_seek(Resultset as Object, Column as Numeric)
+
 
+
The mysql_fetch_field() function returns an object containing information of a field from a recordset
+
Object = rdo_fetch_field(Resultset as Object, Column as Numeric)
+
Object = mysql_fetch_field(Resultset as Object, Column as Numeric)
+
 
+
The mysql_fetch_lengths() function returns the length of the contents of each field in a row
+
Object = rdo_fetch_lengths(Resultset as Object)
+
Object = mysql_fetch_lengths(Resultset as Object)
+
 
+
The mysql_field_table() function returns the name of the table where a specified field is located
+
Character = rdo_field_table(Resultset as Object, int field_offset)
+
Character = mysql_field_table(Resultset as Object, int field_offset)
+
 
+
The mysql_field_name() function returns the name of a field in a recordset
+
Character = rdo_field_name(Resultset as Object, Column as Numeric)
+
Character = mysql_field_name(Resultset as Object, Column as Numeric)
+
 
+
The mysql_field_type() function returns the type of a field in a recordset
+
Character = rdo_field_type(Resultset as Object, Column as Numeric)
+
Character = mysql_field_type(Resultset as Object, Column as Numeric)
+
 
+
The mysql_field_len() function returns the length of a field in a recordset
+
Numeric = rdo_field_len(Resultset as Object, Column as Numeric)
+
Numeric = mysql_field_len(Resultset as Object, Column as Numeric)
+
 
+
The mysql_field_flags() function returns the flags of a field in a recordset
+
Character = rdo_field_flags(Resultset as Object, Column as Numeric)
+
Character = mysql_field_flags(Resultset as Object, Column as Numeric)
+
 
+
The mysql_result() function returns the value of a field in a recordset
+
Character = rdo_result(Resultset as Object, Row as Numeric, char field)
+
Character = mysql_result(Resultset as Object, Row as Numeric, char field)
+
 
+
The mysql_free_result() function frees memory used by a result handle
+
Numeric = rdo_free_result(Resultset as Object)
+
Numeric = mysql_free_result(Resultset as Object)
+
 
+
The mysql_free_object() function frees memory used by an object
+
Numeric = rdo_free_object(Resultset as Object)
+
Numeric = mysql_free_object(Resultset as Object)
+
 
+
The mysql_real_escape_string() function escapes special characters in a string for use in an SQL statement
+
Character = rdo_real_escape_string(string as character [, Connection as Numeric] )
+
Character = mysql_real_escape_string(string as character [, Connection as Numeric] )
+
 
+
The mysql_info() function returns information about the last query
+
Character = rdo_info( [Connection as Numeric ] )
+
Character = mysql_info( [Connection as Numeric ] )
+
 
+
The mysql_ping() function pings a server connection or reconnects to it if there is no connection
+
Numeric = rdo_ping( [Connection as Numeric] )
+
Numeric = mysql_ping( [Connection as Numeric] )
+
 
+
The mysql_thread_id() function returns the current thread ID
+
Numeric = rdo_thread_id()
+
Numeric = mysql_thread_id()
+
 
+
The mysql_stat() function returns the current system status of Recital
+
Numeric = rdo_stat( [Connection as Numeric] )
+
Numeric = mysql_stat( [Connection as Numeric] )
+
 
+
The mysql_get_client_info() function gets information about Recital
+
Character = rdo_get_client_info()
+
Character = mysql_get_client_info()
+
 
+
The mysql_get_host_info() function gets information about Recital
+
Character = rdo_get_host_info()
+
Character = mysql_get_host_info()
+
 
+
==See Also==
+
[[rdo_get_client_info()]], [[rdo_get_host_info()]], [[rdo_info()]], [[rdo_ping()]], [[rdo_stat()]], [[rdo_thread_id()]]
+

Latest revision as of 11:57, 22 June 2010

Purpose

Connect to a data source


Syntax

RDO_CONNECT(<expC1>, <expC2>, <expC3>, <expC4> [, <expC5>])

MYSQL_CONNECT(<expC1>, <expC2>, <expC3>, <expC4> [, <expC5>])


See Also

RDO_AFFECTED_ROWS(), RDO_CLOSE(), RDO_DATA_SEEK(), RDO_ERRNO(), RDO_ERROR(), RDO_EXEC(), RDO_FETCH_ARRAY(), RDO_FETCH_ASSOC(), RDO_FETCH_FIELD(), RDO_FETCH_LENGTHS(), RDO_FETCH_OBJECT(), RDO_FETCH_ROW(), RDO_FIELD_FLAGS(), RDO_FIELD_LEN(), RDO_FIELD_NAME(), RDO_FIELD_SEEK(), RDO_FIELD_TABLE(), RDO_FIELD_TYPE(), RDO_FREE_OBJECT(), RDO_FREE_RESULT(), RDO_GET_CLIENT_INFO(), RDO_GET_HOST_INFO(), RDO_INFO(), RDO_LIST_DBS(), RDO_NUM_FIELDS(), RDO_NUM_ROWS(), RDO_PING(), RDO_QUERY(), RDO_REAL_ESCAPE_STRING(), RDO_RESULT(), RDO_SELECT_DB(), RDO_STAT(), RDO_THREAD_ID(), RDO_UNBUFFERED_QUERY()


Description

The RDO_CONNECT() function is used to connect to a data source. The numeric value returned should be saved to a variable to be used by other functions to reference the connection. Connection references start from 0 and correspond to the cursor/workarea -1. If RDO_CONNECT() returns -1, the connection failed.


Keywords Description
<expC1> Servertype: "recital", "oracle", "db2", "mysql" or "postgres"
<expC2> Hostname: IP address or character name
<expC3> Username: account used to access the data source
<expC4> Password: password for account above
<expC5> Database: database to connect to


Example

conn = rdo_connect("mysql","localhost", "user", "pass", "test")
if conn > -1
    rdo_exec("create table mytable (phrase char(20))", conn)
    rdo_exec("insert into mytable values ('Hello world')")
    echo rdo_affected_rows()
    rdo_close(conn)
endif


Products

Recital, Recital Server