I have a CLOB column in a table. When i query the table and try to echo the data, i get something like
Resource id #102
I searched about this and found this POST . Tried the given solution from it in zend framework like this below:
$clobContent = $data['TEXT']->load();
$data contains the result of the query.
But gets the following error
Fatal error</b>: Call to a member function load() on a non-object
How do i get the contents of the CLOB in zend framework?
Somehow after changing the db adapter from PDO_OCI to Oracle worked for me. Had read in some post that PDO_OCI had problems with reading CLOBS.
resources.db.adapter = oracle // in application.ini
The code below worked for me, not sure of it but can try this and let me know if it worked
$select = $this->_dbAdpt->select()
->from($this->_name)
->where($this->_dbAdpt->quoteInto('LOWER(URL) = ?', strtolower($url)))
->where($this->_dbAdpt->quoteInto('VERSION = ?', $version))
;
$row = $this->_dbAdpt->fetchRow($select);
return $row['CONTENT']->load();
Related
I am using cakephp framework. I need SQL for following statement:
$vehicle = $this->Vehicle->find('all');
How can I do that?
Please guide me.
Thank you,
Trupti
For Cakephp 1.x, you could use following code to get the last query
$dbo = $this->Vehicle->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
echo $lastLog['query'];
Alternatively, To get all the Queries executed in the Current HTTP Request, you can use the following code
$db =& ConnectionManager::getDataSource('default');
$db->showLog();
You have to set the Debug Mode to 2 for this to work.
I have a stored procedure that client has made.
Now I have to access it and process data in my laravel app.
I have no problems with connecting to SQL but the problems starts when passing in parameters.
Here is my code:
$connections = DB::connection('sqlsrv')
->select(EXEC [stored].[procedure].[here] $param1, $param2);
The error I got back is:
The active result for the query contains no fields
I have searched for many hours in forums and here is what I have found:
$connections = DB::connection('sqlsrv')
->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));
Error I got back is:
The active result for the query contains no fields.
I have installed SQL driver and OBDC driver.
Any help would be much appreciated
Don't know if this will help but this answer suggests you put your DB::raw around just the params instead of the EXEC stored.proc.name.
So instead of
$connections = DB::connection('sqlsrv')->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));
Try
$connections = DB::connection('sqlsrv')->select('EXEC stored.proc.name' . DB::raw($param1, $param2));
OK. So I found out the issue.
It turns out the client sent me over a variable with xml.
As far as I figured out from Microsoft docs then you cant pass xml as a varable because if you call the SP from an application it is gonna pass it as an array and application cant parse xml into array directly. You have to do it on your own.
What can be done instead is to pass xml as a value of an array and then take it from there.
I'm trying to return a single document from the database by it's ID.
This is what I have right now.
$id = "5a30ff2c3afc720394000ac2";
$collection = (new \MongoDB\Client(DB_HOST))->DB->posts;
$post = $collection->findOne(['_id' => $id]);
findOne() returns nothing while find() seems to be working. MongoDB documentations mentions that it would not return anything if no document were to be found. However, the document does seem to be in my database.
I have also tried PHP MongoDB documentation example.
$post = $collection->findOne(['_id' => new \MongoId($id)]);
This returns a no class found error.
Mongo by default stores _id as Object
Try this
$collection->findOne(['_id'=> new \MongoDB\BSON\ObjectId("$mongoId")]);
You are using MongoDB driver, but using Mongo driver object.
Using steam condenser with laravel 4 and installed it via composer.
I am trying to get the players inventory for dota2. I tried:
WebApi::setApiKey('*******');
$inventory = DotA2Inventory::createInventory('username');
But it gives me:
Class 'DotA2Inventory' not found
I am doing this on my User Controller.
Here is the inventory class, and here is the dota2 inventory class.
I am just trying to extract the inventory of the user so I can display it, complete with image, name, rarity and other item info.
UPDATE
So I have found that I forgot to add this:
require_once STEAM_CONDENSER_PATH . 'steam/community/GameInventory.php';
Now with that I am getting another error: Trying to get property of non-object
protected function _getJSONData($interface, $method, $version = 1, $params = null) {
$data = $this->getJSON($interface, $method, $version, $params);
$result = json_decode($data)->result;
Additional Info
I am working with version 1.3.7 of steam-condenser. (checked my steam-condenser.php to confirm this)
The error is "Trying to get property of non-object" on line 190 of WebApi.php
$result = json_decode($data)->result;
Specifically was trying to get the dota 2 inventory of the user 76561198115395760.
Having a look at the answer to this question and your issue on GitHub this may be caused by your PHP environment (WAMP) on Windows.
Please try using XAMPP (or a manual installation).
json_decode() will probably return an array. Try
$array = json_decode($data);
$result = $array['result'];
I have been looking for a solution that allows load data queries with zend framework like:
LOAD XML LOCAL INFILE '$dbFile' INTO TABLE mytable ROWS IDENTIFIED BY '<object>';
When I try to execute this query, i get the following error:
Warning: PDO::exec() [pdo.exec]: LOAD DATA LOCAL INFILE forbidden
However if I output the query and copy/paste it into an editor like HeidiSQL the query works.
I searched for an answer and found that I should set the driver option PDO::MYSQL_ATTR_LOCAL_INFILE but it does not seem to work.
I would like to use application.ini to set the driver option:
resources.multidb.mydb.adapter = "Pdo_Mysql"
resources.multidb.mydb.dbname = "mydb"
resources.multidb.mydb.username = "myuser"
resources.multidb.mydb.password = "mypass"
resources.multidb.mydb.driver_options.PDO::MYSQL_ATTR_LOCAL_INFILE = true
resources.multidb.mydb.driver_options.1001 = true
I tried it the following way too but got the same error:
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'testing');
$dbParams = $config->resources->multidb->mydb->toArray();
$dbParams['driver_options'] = array(PDO::MYSQL_ATTR_LOCAL_INFILE => '1');
$db = Zend_Db::factory($config->resources->multidb->mydb->adapter, $dbParams);
Am I overlooking something? Or maybe setting the options wrong? I also read that mysql must be compiled with --enable-load-data or something but the query works with an sql editor so it should work through php.
I found an interesting implementation of local infiles in the Rend (Rapid Zend) Framework.
Basically, the file has a class for the PDO object and has a method like this:
/**
* Set the local infile flag
*
* #param boolean $allowLocalInfile
* #return Rend_Factory_Database_Pdo_Mysql
*/
public function setAllowLocalInfile($allowLocalInfile)
{
$this->_options["driver_options"][PDO::MYSQL_ATTR_LOCAL_INFILE] = $allowLocalInfile;
return $this;
}
I'm sure some more browsing in that open source repository would reveal some tricks to solve your problem.