I'm trying to create a table in laravel 4 from a construct function, but it's not working.
I have search online for a proper way to do this which led me to raw. But raw expects a table name, or at least that is what I made of it.
So I looked a little further and found a DB::only function. But it throws this error:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\MySqlConnection' does not have a method 'only'
So there you have it, I would really like a solution for this seeing my project requires it.
Well, found it:
DB::statement($sql);
Related
New to CakePHP 3.3. I looked across multiple sites (Stack Overflow, W3Schools, etc.) but cannot find an answer to:
What does this piece of code mean/do in a CakePHP tutorial:
public function initialize (array $config)
1) public: I understand this can either be public, private, or protected
2) function: Is this creating a function called "initialize()"?
3) initialize(): I understand this is a method built into CakePHP, but what does it do?
4) array $config: Are these two words combined or are they separate of each other? Why do I need both words, what is the influence of one on the other?
Background: This comes from the CakePHP tutorial and is found in multiple .php files. Not sure what is php code and what is unique CakePHP terminology.
I think This is very good question...!!! This question is applied for all framework not bounded only for CakePHP.
function my_function(array $arr, int $int, $bool $active)
{
/// function body
}
In technical it knows as Type Hinting
Type declarations allow functions to require that parameters are of a
certain type at call time. If the given value is of the incorrect
type, then an error is generated: in PHP 5, this will be a recoverable
fatal error, while PHP 7 will throw a TypeError exception.
To specify a type declaration, the type name should be added before
the parameter name. The declaration can be made to accept NULL values
if the default value of the parameter is set to NULL.
Check about valid types paramater
Reference: http://php.net/manual/en/functions.arguments.php
I see at least one great advantage of using type hinting: readability. It's easier to see what kind of parameter a function/method expects.
Some will see this as a drawback that if you don't respect a type hint and pass some not-type-valid parameter, you'll get a catchable fatal error. However,
I personally think it forces the developer to respect your interfaces more
It allows your code to just work with the received parameters.
The generated error is catchable.
Question of Performance?
Making the decision of using type hints or not using type hints should not be the result of performances considerations. You should use or not use the feature.
Even if there is some performance impact, it should be pretty minimal. I would say there are many parts of your code that you should optimize before considering this.
Conclusion
In conclusion, a personal opinion: I quite often use those type hints, just so:
Other Developers using my code know what they are expected to pass in (they don't always read the documentation...)
If they don't do what is expected, it fails; hard; in a way they immediately notice
My code doesn't have to check if the received parameter is of the right type: I know it is, as PHP enforces that for me.
Cakephp find data in controller also can with sql syntax,
example :
$this->Post->find('all');
in sql :
select * from posts
convert query to cakephp find syntax is available at http://dogmatic69.com/sql-to-cakephp-find-converter
but whether there is any link for me if I wanna convert my cakephp find to query..
Thanks in advance...
If I got what you are asking, here is the answer
SQL calls that you can’t or don’t want to make via other model
methods can be made using the model’s query() method (though this
should only rarely be necessary).
query() uses the table name in the query as the array key for the returned data, rather than the model name. For example:
$this->POST->query("SELECT* from posts;");
Here is the link for cakephp documentation
So I know that you can query a table using PHP as so:
$projectmanager=DB::table('Table_name')->distinct()->select('Table_Column')->get();
I want to know if you can do the same type of thing with a SQL Server View. I have tried the following:
$view=DB::view('View_Name')->select('View_Column')->get();
But I get the following error:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\SqlServerConnection' does not have a method 'view'
Are you using Laravel by chance? Whatever the framework, you are calling a method DB::view that doesn't exist, so some class magic fails.
To answer question, yes. To PHP they are seen the same as a regular table, treat it as such for querying (though you cannot manually update them of course).
$projectmanager=DB::table('View_name')->distinct()->select('View_column')->get();
I got used to use Grocery CRUD library which eases CRUD process. When I'm going to use the edit process, The URI is would be some thing like http://www.example.com/users/get_users/edit/userID(num).
The issue is, If one of the users removes the userID this will gives an error due to the required parameter by edit method, So that I have tried to use Codeigniter routing as below
$route['users/get_users/edit'] = "users/get_users";
But this didn't work..!
Any idea please...
$route['users/get_users/edit/:num'] = "users/get_users";
It should be like this. And I think you getting error message because "users/get_users" still expects userID. Its better to come up with the error message as well.
I'm working on a Symfony app that uses Doctrine as the ORM. I want to run a query with an WHERE foo IN (bar) clause, and I'm adding the IN bit like so:
$query->andWhereIn('p.foo', $bar);
where $bar is an array of id numbers. Browsing the docs and trying out a few combinations, I was unable to make Doctrine treat the parameter I'm passing there as a named parameter.
As a result, I'm forced to use positional parameters for the rest of the query, too, as you can't mix the two. What, if anything, am I missing?
I wrote a patch for this http://www.doctrine-project.org/jira/browse/DC-1003?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel that was never committed but it does handle this scenario..
andWhereIn() is simply a proxy method for whereIn()
Have you tried to use whereIn() or did you skip directly to andWhereIn()?