zend framework 3 - get sql string - zend-framework3

I need to get the real sql string for a complex zend db sql abstraction.
ZF2 had a function for this:
$sql->getSqlstringForSqlObject($select);
is there an equivalent in ZF3 ?

Yes. You can use echo $sql->getSqlStringForSqlObject($select) to see the sql query. but recommnded way to do this now in ZF3 is echo $sql->buildSqlString($select);

I think it's same as in ZF2
//Zend\Db\Sql\Select
$select = $this->getSql()->select();
echo #$select->getSqlString();

Related

How to you use Azure documentdb using php

Is any one know how to work with azure document db using php.
i want to create collection add the data in the document db using php.
please send any sample code for it.
http://azure.microsoft.com/en-in/services/documentdb/
Thanks
Thanigaivelan
DocumentDB currently does not have an official PHP client SDK available.
You can interact with DocumentDB using the REST API.
Alternatively, you could look for unofficial 3rd-party SDKs like this one (I'm not sure how well supported this project is - but the source code looks to be good reference for interacting with the REST API).
Documentdb offers a REST API, so what you need is a REST API client. You can write one on your own, or use one of the 3 available on github (search for php documentdb)
Basically you need to request the resource you need via POST and add the required headers using CURL.
The only tricky part is the authorization token you need to create based on various information.
Here is a code snippet for the token :
function gettoken($master_key,$vrb,$rtype,$rid,$da_date) {
$key = base64_decode($master_key);
$st_to_sign = $vrb . "\n" .
$rtype . "\n" .
$rid . "\n" .
$da_date . "\n" .
"\n";
$sig = base64_encode(hash_hmac('sha256', strtolower($st_to_sign), $key, true));
return $sig;
}
My repo on github is a good , simple way to start but not oop. (https://github.com/upggr/documentdb-for-php)
There are currently 2 more repos that provide the full API functionality via a class :
The one from cocteau666 as mentioned in the previous comment and one from crassaert (https://github.com/crassaert/php-azure-documentdb)
For some reason, there is not much interest yet on people implementing this with php, I hope this changes soon.

How to call an Oracle procedure w/ OUT parameter in WSO2ESB?

versions:
- WSO2 4.6.0
- Oracle 11g
I Have this procedure in an Oracle DB:
PROCEDURE SEARCHCONTRACT ( CONTRACTNUM IN OKC_K_HEADERS_B.CONTRACT_NUMBER%TYPE
, cur_out IN OUT RefCursor)
....
The procedure is working fine!
Note that cur_out IN OUT RefCursor!
I have no clue on how to handle that parameter in a DBLookup mediator! This mediator does not have any place to inform whether each parameter is "IN" or "OUT" and I'm not sure if setting the direction (IN/OUT) would be enough.
Thanks in advance for any help!
I believe you can use WSO2 Data Services Server (DSS) or your requirement.
You can download WSO2 DSS from http://wso2.com/products/data-services-server/
It has support for Oracle RefCursor.
You can then use the data service via WSO2 ESB.
Following article might help.
http://wso2.com/library/tutorials/use-oracle-ref-cursors-wso2-data-services-server
just a thought. You could try to implement a pl/sql function that call that prodecure and return the value. This way you could get the result with the ddl SELECT MyfUCNTION(PARAM1) FROM DUAL.
You could also convert the procedure into a function.
Hope it helps!

jdbc sqlite support allowmultiquery

I would like to demonstrate SQL injection using Java and sqlite. I'm attempting to execute two queries at the same time with SQL injection. The user is to prematurely end the statement using ;, then add another entry using an insert statement.
Mysql JDBC using allowMultiQueries=true in the connection string.
How can I do this using sqllite?
TIA
allowMultiQueries as a MySQL-specific connection parameter.
I do not know of any SQLite JDBC driver that would allow multiple commands in one query.
Therefore, this kind of SQL injection attack is not possible.
Your best bet would be to construct some query like this:
SELECT * FROM Users WHERE Name = 'admin'--' AND Password = 'whatever'
or this:
SELECT *
FROM Users
WHERE Name = 'admin'
AND Password = 'whatever' or Name='admin'

Passing a stream or a String to Flyway API instead of locations

I was wondering if there is a way for Flyway to accept an actual SQL migration as a string or a stream instead of searching for it on a classpath?
I'm constructing the SQL migration in Java on the fly and would like to call Flyway API and pass the migration as a paramter.
Please, let me know if this is possible.
Thank you
Not entirely what you are asking for, but looks like Java-based migrations might be a solution.
Basically instead of V1_0__script.sql you write V1_0__script.java class implementing JdbcMigration. Inside that class you have access to JDBC Connection:
class V1_0__script implements JdbcMigration {
public void migrate(Connection connection) throws Exception {
//...
}
}
In migrate() you are free to run your custom SQL queries.
There is no API available for this.
However, if you construct your SQL on the fly, it surely must be possible to construct it one statement at a time. Each statement can then be executed using the Connection parameter you get in a JdbcMigration

FoxPro Database and asp.net

I have a website that uses asp.net 3.5 and Sql server 2008 as backend data store . now we want to add a new page to our website . but the data that we want to share in this page is already being created and saved by a FoxPro software in one of our local systems.
I've no experience in FoxPro . is there any way to use this data in our site ? specially without being have to create a new database in server and importing or writing all records all over again ? what is the best way in such a situation ?
by the way , is it possible to change the extension of a FoxPro database or not ? something like Database.customExt ?
You can connect to a FoxPro database using an OLEDB datasource in ADO.NET. It's up to you whether you feel the need to import the data into SQL Server or just access it directly in FoxPro. It would depend on whether you want to join the data with the SQL Server data in queries for one thing.
In addition to the answers that you already got. You might be interested in using LINQ to VFP or VFP Entity Framwork Provider to make the data access even easier by using LINQ.
You could create a linked server to this Foxpro Database.
Also, Foxpro tables can have any extension. However, you'll have to specify the extension when using the table or database. For Example:
OPEN DATABASE MyFoxProDatabase.customExt
USE mytable.custonExt
You have several options for structuring your data access to FoxPro. You can put the ADO.NET data access code in the codebehind, in it's own c# library or use the objectdatasource for 2 way binding.
private void LoadData(string parameter)
{
string sql = "SELECT a.myfield FROM mytable.customExt a WHERE a.whereField=?";
using(OleDbConnection conn = new OleDbConnection(myConnectionString))
{
using (OleDbCommand command = new OleDbCommand(sql, conn))
{
command.Parameters.AddWithValue("#Parameter", parameter);
try
{
conn.Open();
using(OleDbDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
{
myGridView.DataSource = dr;
myGridView.DataBind();
}
}
catch (Exception ex)
{
throw;
}
}
}
}
Here is a sample connection string to use in web.config:
<add name="myData" connectionString="Provider=VFPOLEDB.1;Data Source=C:\MyFiles\" providerName="System.Data.OleDb"/>
I belive ou can use a custom extension to your FoxPro tables and databases. All your SQL statements would then need to explicitly use that extension.
SELECT t.MyField FROM MyTable.customExt t
While you can change the extension for a Visual FoxPro table, that only affects the DBF file. If the table has any memo fields, there's an associated FPT file, for which you can't change the extension. Similarly, if the table has an associated index file, it must have a CDX extension.
So, if the reason you want to change the extension is to allow multiple tables with the same filestem, don't. It's a good way to really mess things up.

Resources