Switch to: V11V10V9V8V7V6V5

valentina_db_query()

Declaration

resource valentina_db_query ( 
               string database, 
               string query,
               [array bind_values]
               [resource link_identifier,]
)  

Parameters

Name Description
database The name of the database that will be selected.
queryThe VServer query.
link_identifierThe VServer connection. If the link identifier is not specified, the last link opened by valentina_connect() is assumed. If by chance no connection is found, an E_WARNING level warning is generated.
bind_valuesAn array containing values to be binded into sql query

Note: Whatever combination of aruments you use the link identifier should be last.

Description

Selects a database, and executes a query on it.

Return Values

Returns a positive VServer result resource to the query result, or FALSE on error. The function also returns TRUE/FALSE for INSERT/UPDATE/DELETE queries to indicate success/failure.

Examples

Example 1.

<?php
 
if (!$link = valentina_connect('val_host', 'val_user', 'val_password')) {
   echo 'Could not connect to valentina';
   exit;
}
 
$sql    = 'INSERT INTO table_test(payment, message) values( 12, "Hello sam!" )';
$result = valentina_db_query('val_dbname', $sql, $link);
 
if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'VServer Error: ' . valentina_error();
   exit;
}
 
valentina_free_result($result);
 
?>

Example 2 - binding.

<?php
 
if (!$link = valentina_connect('val_host', 'val_user', 'val_password')) {
   echo 'Could not connect to valentina';
   exit;
}
 
 
$sql    = 'INSERT INTO table_test(payment, message) values( :1, :2 )';
$arr[] = 12;
$arr[] = 'Hello world!';
$result = valentina_db_query('val_dbname', $sql, $arr, $link );
 
if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'VServer Error: ' . valentina_error();
   exit;
}
 
valentina_free_result($result);
 
?>

Notes

Note: Remember - this function works like valentina_select_db() and valentina_query() ran one-by-one, It means that this functiondoes not switch back the currently selected database.

Compatibility: This function, as in MYSQL API is not recommended to use - use instead valentina_select_db() and valentina_query().

See Also