Switch to: V11V10V9V8V7V6V5

valentina_query()

Declaration

resource valentina_query(
	string Query
	[,resource linkID]
	[,array binds]
	[,integer inCursorLocation = VALENTINA_CURSORLOCATION_CLIENTSIDE]
	[,integer inLockType = VALENTINA_LOCKTYPE_READONLY]
	[,integer inCursorDirection = VALENTINA_CURSORDIRECTION_FORWARDONLY]  )
)  

Parameters

Name Description
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.

Constants

Name Constants
CursorLocationVALENTINA_CURSORLOCATION_CLIENTSIDE, VALENTINA_CURSORLOCATION_SERVERSIDE
LockTypeVALENTINA_LOCKTYPE_NOLOCKS, VALENTINA_LOCKTYPE_READONLY, VALENTINA_LOCKTYPE_READWRITE
CursorDirectionVALENTINA_CURSORDIRECTION_FORWARDONLY, VALENTINA_CURSORDIRECTION_RANDOM

Description

Runs SQL query.

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;
}
 
valentina_select_db('test_database');
$sql    = 'INSERT INTO table_test(payment, message) values( 12, "Hello sam!" )';
$result = valentina_query( $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;
}
 
valentina_select_db('test_database');
 
$sql    = 'INSERT INTO table_test(payment, message, description) values( :1, :2, :3 )';
$arr[] = 12;
$arr[] = 'Hello world!';
$arr[] = null; // passing NULL value
$result = valentina_query(, $sql, $arr, $link );
 
if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'VServer Error: ' . valentina_error();
   exit;
}
 
valentina_free_result($result);
 
?>

Example 3 - Binding Binary Values

[NEW for VPHP4]

<?php
 
if (!$link = valentina_connect('val_host', 'val_user', 'val_password')) {
   echo 'Could not connect to valentina';
   exit;
}
 
valentina_select_db('test_database');
 
// Read binary file
$filename = "test.jpg";
$f        = fopen( $filename, "rb" );
$data     = fread( $f, filesize($filename) );
fclose( $f );	
 
$sql    = 'INSERT INTO table_test(payment, message, image) values( :1, :2, :3 )';
$arr[] = 12;
$arr[] = 'Hello world!';
$arr[] = $data; 
 
// Query
$result = valentina_query(, $sql, $arr, $link );
 
if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'VServer Error: ' . valentina_error();
   exit;
}
 
valentina_free_result($result);
 
?>

Example 4 - Binding Binary Values as Resource

[NEW for VPHP5]

<?php
 
if (!$link = valentina_connect('val_host', 'val_user', 'val_password')) {
   echo 'Could not connect to valentina';
   exit;
}
 
valentina_select_db('test_database');
 
// Read binary file
$f     = fopen( "test.jpg", "rb" );
 
$sql   = 'INSERT INTO table_test(payment, message, image) values( :1, :2, :3 )';
$arr[] = 12;
$arr[] = 'Hello world!';
$arr[] = $f; 
 
// Query
$result = valentina_query(, $sql, $arr, $link );
 
fclose( $f );	
 
if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'VServer Error: ' . valentina_error();
   exit;
}
 
valentina_free_result($result);
 
?>

See Also