Open tr33m4n opened 8 years ago
I've got it up to the following point when trying to access an MSSQL database. I have created the customers table however I get the following error
Table 'customers' doesn't exist in database when dumping meta-data for TkcApi\Models\Customers
Any ideas?
I'm presuming the changes I've made are allowing the MSSQL adapter and dialect to do their thing, but perhaps there's an issue with how the table is looked up? I'm running Microsoft SQL Express 2012
Which branch did you pull? Be sure to use the 2.x branch... at this point, master doesn't work, but 2.x definitely will.
Ah, thanks for that. I appear to have got a little further using the 2.x branch, however now it cannot find the table "name" that definitely exists in the table:
Column 'name' doesn't belong to any of the selected models (1), when preparing: SELECT * FROM TkcApi\Models\Customers ORDER BY name
Any further insights?
Cheers
If you can send/post the bit of code, I can compare it to what I have working.
This is the index function of my controller:
public function index() {
$phql = "SELECT * FROM TkcApi\Models\Customers ORDER BY name";
$customers = $this->modelsManager->executeQuery($phql);
$data = array();
foreach ($customers as $customer) {
$data[] = array(
'id' => $customer->id,
'name' => $customer->name,
'contacts' => $customer->contacts,
'addresses' => $customer->addresses,
'credit_limit' => $customer->credit_limit
);
}
echo json_encode($data);
}
And this is the Customers model:
namespace TkcApi\Models;
use Phalcon\Mvc\Model;
class Customers extends Model
{
public function getSource() {
return "customers";
}
}
This controllers and models appear to be loaded correctly (to the best of my knowledge)
Cheers
Let's try something simpler.
I couldn't get it to work using name spaces either (I will work with Kevin to see if he can fix), but I do know this will work:
$test = Customers::find(array("limit" => 30, "order" => "name ASC"));
foreach($test as $customer) {
$data[] = array(
'id' => $customer->id,
'name' => $customer->name,
'contacts' => $customer->contacts,
'addresses' => $customer->addresses,
'credit_limit' => $customer->credit_limit
);
}
echo json_encode($data);
Hmm, I'm not having much luck with this either... Perhaps I've not setup the SQL server properly? Although it does find the database so I'm not too sure why it wouldn't find the table. This is the error I get when using the above:
Column 'name' doesn't belong to any of the selected models (1), when preparing: SELECT [TkcApi\Models\Customers].* FROM [TkcApi\Models\Customers] ORDER BY name ASC LIMIT :AP0:
I guess you're not using namespaces though. Hmm
Did you take out all of the references to the name space? I am still seeing it in your debug output. I removed it from everything for my testing.
I have now, yes, however more errors have occurred!
Notice: Undefined index: offset in /Users/danieldoyle/Projects/tkc-api/public_html/library/db/dialect/Mssql.php on line 331
Notice: Trying to get property of non-object in /Users/danieldoyle/Projects/tkc-api/public_html/controllers/CustomersController.php on line 21
Notice: Trying to get property of non-object in /Users/danieldoyle/Projects/tkc-api/public_html/controllers/CustomersController.php on line 22
Notice: Trying to get property of non-object in /Users/danieldoyle/Projects/tkc-api/public_html/controllers/CustomersController.php on line 23
Notice: Trying to get property of non-object in /Users/danieldoyle/Projects/tkc-api/public_html/controllers/CustomersController.php on line 24
Notice: Trying to get property of non-object in /Users/danieldoyle/Projects/tkc-api/public_html/controllers/CustomersController.php on line 25 [{"id":null,"name":null,"contacts":null,"addresses":null,"credit_limit":null}]
When I switch your query out for my original one the Undefined index error goes away, however the errors above still occur. It looks like it's not receiving any data therefore not populating the array
Can you drop your latest code snippet in here? I want to compare again. I think we are close! Thanks!
Yup, here's the controller
<?php
use Phalcon\Http\Response;
use Phalcon\Mvc\Controller;
class CustomersController extends Controller
{
public function index() {
$customers = Customers::find(array("limit" => 30, "order" => "name ASC"));
$data = array();
foreach ($customers as $customer) {
$data[] = array(
'id' => $customer->id,
'name' => $customer->name,
'contacts' => $customer->contacts,
'addresses' => $customer->addresses,
'credit_limit' => $customer->credit_limit
);
}
echo json_encode($data);
}
}
And the model:
<?php
use Phalcon\Mvc\Model;
class Customers extends Model
{
public function getSource() {
return "customers";
}
}
I'm using the latest Phalcon btw, not sure if that makes any difference at the moment.
Btw, the $customers object is populated and has reference to the fields in the table which is a good sign, however even in the object the fields are returning blank
I am using 2.0.2, but I don't think that should make a difference. I will upgrade my DLLs and see if it stops working here. This is the exact code I am using:
public function indexAction() {
$test = Personas::find(array(
"limit" => 30, "estado = 'CA'", "order" => "nombre DESC")
);
//$test = Personas::findFirst();
echo count($test) . "<p>";
foreach($test as $user) {
$data[] = array(
"id" => $user->id,
"nombre" => $user->nombre
);
}
echo json_encode($data);
$this->view->disable();
return;
}
When you count() customers, how many are you getting?
Using count returns "2", which is the amount of records I have currently, yet no data... I'll investigate more tomorrow, thank you for your help.
Just a heads up, I had to update some of the functions in the dialect and adapter as they were returning strict errors such as:
Strict Standards: Declaration of Twm\Db\Adapter\Pdo\Mssql::executePrepared() should be compatible with Phalcon\Db\Adapter\Pdo::executePrepared(PDOStatement $statement, array $placeholders, $dataTypes) in /Users/danieldoyle/Projects/tkc-api/public_html/library/db/adapter/Mssql.php on line 10
I'm not sure whether that has maybe screwed the plugin up, but I had got to this point having done this, I couldn't really get any further
Yes, when I upgraded to 2.0.6, I began seeing these as well. I suspect you just needed to go through and remove the array typing to get it to work?
Have you gotten it to work now?
No unfortunately, I had to fix those errors just to get it to the point I initially asked for help... Just doesn't seem happy at all.
Yes, when I upgraded to 2.0.6, I began seeing these as well. I suspect you just needed to go through and remove the array typing to get it to work?
Have you gotten it to work now?
— Reply to this email directly or view it on GitHub https://github.com/fishjerky/phalcon-mssql/issues/4#issuecomment-126706539 .
That's weird, email wasn't meant to include the quoted text, ah well. I've even downgraded to 2.0 just to see if that has made any difference, alas no, still no data
The version that I had working (and still do) is 2.0.2. If you're showing a count of 2, then you have data. Can you print_r() those two records? What does it show?
Hmm, even running Phalcon 2.0.2 I get the same strict warnings and fatals I got when using a newer version... How did you not encounter these previously? What version of PHP are you running? Also, what level of error reporting are you running?
print_r just dumps the object without populated fields (and many recursions) http://pastebin.com/SUNsA7k0
PHP 5.6.3 is what I am running. You? If you want to send me a dump of your table, I'll see if I can at least get it running on 2.0.2. I have reached out to Kevin, he's aware of the issue with 2.0.6 and I suspect he'll have a fix for it quickly.
5.5.9, but I was running 5.6 before... Had to downgrade for another project. Ok, thank you, there's not much in the table tbh, just 2 rows to try and get something up and running! https://www.dropbox.com/s/efde4x5hk7xupj5/dbo.sql?dl=0
Sorry it took me so long to get to this, but I have it working.
public function testAction() {
$customers = Customers::find(array(
"limit" => 30,
"order" => "id DESC"
));
echo count($customers) . "<br />";
foreach($customers as $customer) {
$data[] = array(
'id' => $customer->id,
'name' => $customer->name,
'contacts' => $customer->contacts,
'addresses' => $customer->addresses,
'credit_limit' => $customer->credit_limit
);
}
print json_encode($data);
}
And the model:
use \Phalcon\Mvc\Model;
class Customers extends \Phalcon\Mvc\Model {
}
Basically the same thing we've already been over.
So, maybe it's the adapter and dialect files? Here is the latest that I have: https://www.dropbox.com/s/lrakkezhc1kdmoj/Mssql.php?dl=0 https://www.dropbox.com/s/w2g77c3yhl3jur7/Mssql.php?dl=0
Are you on Linux or Windows? I can send you the 2.0.2 DLL if you need it.
The other thing I can think of that's different is the config:
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Twm\Db\Adapter\Pdo\Mssql',
'host' => '<your server>',
'username' => '<your user>',
'password' => '<your pass>',
'dbname' => '<your db>',
'pdoType' => 'sqlsrv',
'dialectClass' => 'Twm\Db\Dialect\Mssql',
'schema' => 'dbo',
'version' => '2014'
),
'application' => array(
'controllersDir' => APP_PATH . '/app/controllers/',
'modelsDir' => APP_PATH . '/app/models/',
'migrationsDir' => APP_PATH . '/app/migrations/',
'viewsDir' => APP_PATH . '/app/views/',
'pluginsDir' => APP_PATH . '/app/plugins/',
'libraryDir' => APP_PATH . '/app/library/',
'cacheDir' => APP_PATH . '/app/cache/',
'baseUri' => '/',
)
));
There are two new properties: schema and version.
Sorry that I don't know how to help. I don't have Phalcon 2.x and MSSQL at same environment. (some other guy provide his own server for me, and i can't login right now)
don't know why I can't install Phalcon 2.x(gcc stops compiling) try to set up both on AWS
Cheers
Thank you for the help, I'll try your config this weekend. I'm running Phalcon and MS Server Express in virtualboxes (all for free, you can download a vm of Windows that's valid for 90 days). In terms of gcc not compiling, is it an out of memory error? If that's the case set up a swapfile/partition then it should work fine
The only error I am now seeing on my side with 2.0.6 has to do with the LIMIT functionality. If you remove that, you should be error free!
Hi guys,
Unfortunately I didn't get anywhere with this :( I've had to switch to using an adapter from Zend. I hope this project gets updated soon, would be nice to use a more native driver.
Cheers
Well that is unfortunate. With the last adapter and dialect files, everything should have gone off without a hitch. Can you tell me what error(s) you encountered?
I can't recall anymore unfortunately. One thing different for me was that I was using the dblib pdo type rather than sqlsrv... There's not a lot of documentation on getting sqlsrv running on a Linux box, so thought it best to move on as the project has a deadline looming
Hi there,
Just wondering whether you might have any time to look at 2.0 support?
Cheers Dan