codeigniter DB Connect issue - codeigniter

I have transferred my CI 2.0 site from one domain to updated PHP version new domain.
But I am getting one problem to connect database or something else, don't know exactly.
object(CI_DB_mysqli_result)#24 (7) { ["conn_id"]=> bool(false)
["result_id"]=> NULL ["result_array"]=> array(0) { }
["result_object"]=> array(0) { } ["current_row"]=> int(0)
["num_rows"]=> NULL ["row_data"]=> NULL }
I am getting this as result when I am calling any query of select etc.
Can anyone help me out what is wrong in it?

Related

ReletableQuery $request->isUpdateOrUpdateAttachedRequest() return null

everyone,
I have a problem with an asset in my project.
I have a BelongsTo relation that I can filter using the relatableQuery method.
However I would like to show different data in case I am in the update.
My code is as follows:
public static function relatableTickets(NovaRequest $request, $query)
{
if ($request->isUpdateOrUpdateAttachedRequest()) {
return $query->where('availability', '>', 0);
}
}
what happens is that the $request->isUpdateOrUpdateAttachedRequest() method returns a null value, the really strange thing is that doing a
var_dump( $request>isUpdateOrUpdateAttachedRequest())
I get a consistent value other than null, I just can't figure out what the problem is, can someone help me, thanks.

Null value parameters not hitting on Web api contoller

This api contoller hit only when first two parameter is non nullable, if both datetime parameter is null,then it is not hitting ,I getting a 404 error , please give a solution
[HttpGet("userReports/{empid:int}/{sdate:DateTime?}/{edate:DateTime?}")]
public IEnumerable<object> usersReport(int empid,DateTime? sDate, DateTime? edate)
{
return employeeDailyStatusService.GetUserReport(empid, sDate, edate);
}
I'm using this url for testing in postman
https://localhost:44308/api/EmployeeDailyStatus/userReports/14/null/null
Any routing will translate you url
https://localhost:44308/api/EmployeeDailyStatus/userReports/14/null/null
as this
https://localhost:44308/api/EmployeeDailyStatus/userReports/14/"null"/"null"
null will be just a string "null".
You just need this url:
https://localhost:44308/api/EmployeeDailyStatus/userReports/14

$model->delete() or $model->save() crashes transaction process: 1305 SAVEPOINT trans3 does not exist

It's been 2 days now I'm trying to fix a problem and am still failing. Thank you to whoever can help on this matter.
The error
I keep getting this message:
Doctrine\DBAL\Driver\PDOException : SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT trans3 does not exist
There is a complex process during an action, and I need to check several tables. As it goes through several functions, the process generates nested transactions.
It's not the first time I use transactions, and even nested transactions, everything worked so far. Only this function triggers the error.
Even if I remove the DB::beginTransaction() and its friends from the function, I stil have the error. Except "trans3" becomes "trans2".
I reduced the function code to the simplest in order to trigger the error:
public function doStuff(Stuff $stuff, User $user)
{
$thing = Thing::where('user_id', $user->id)
->where('other_id', $stuff->id)
->get()
->first();
$thing->delete();
return false;
}
What I already tried
As seen in the simplifed code, removing DB::beginTransaction and such
doesn't prevent the error.
I also tried to set a save operation after changing a property from true to false, with $thing->fill(['property' => false]); $thing->save();, same error. If the property isn't changed from what is in database, no error (for instance $thing->fill(['property' => true]); $thing->save(); triggers no error, because no update triggered).
I tried using DB::raw('raw SQL'), no difference.
I tried DB::delete('RAW SQL');, no difference.
Technical environment
Laravel 5.5
mysql Ver 15.1 Distrib 10.0.36-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
PHP 7.0.32-0ubuntu0.16.04.1
The only solution I have in mind right now is removing all transactions in all parent code. Even if I ignore the danger it represents, the time required for this is out of scope, so I'd like to make sure there is no other alternative.
Does anyone have any idea, lead, anything ?
Thank you for your time.
This answer may come way too late but I was having what seems to be the same problem.
It was only when I decided to try removing the transaction that I found there was an underlying error. One of the inserts was causing an integrity constraint violation error which my tests where reporting as SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT trans2 does not exist.
Once I resolved the underlying error I restored my transaction and everything worked.
In my case, it works in my local environment, but it fails in CI.
Finally, I found the point.
Local MySQL
sql_mode: NO_ZERO_IN_DATE, NO_ZERO_DATE, NO_ENGINE_SUBSTITUTION
CI MySQL
sql_mode: STRICT_TRANS_TABLES, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION
I found that when I created the table, I didn't give the default value of the varchar type, and I forgot to write it when I assigned the value.
Therefore, in my case, the main reason is mysql strict mode.
May be helpful to you.
(By the way, the framework I am using is not laravel. )
This is not a solution, just a workaround, and not really satisfying. But still, it helped me prevent several problems.
I created a TransactionService
class TransactionService
{
/**
* #return bool
* #throws \Exception
*/
public function beginTransaction() {
if(DB::transactionLevel() === 0) {
DB::beginTransaction();
return true;
}
return false;
}
/**
* #param bool $ongoingTransaction
*/
public function commit($ongoingTransaction) {
if($ongoingTransaction === true) {
DB::commit();
}
}
/**
* #param bool $ongoingTransaction
*/
public function rollBack($ongoingTransaction) {
if($ongoingTransaction === true) {
DB::rollBack();
}
}
}
And I use DB transactions only through it:
$sqlOngoingTransaction = Transaction::beginTransaction();
try {
// do stuff
} catch (\Exception $e) {
Transaction::rollBack($sqlOngoingTransaction);
throw($e);
}
Transaction::commit($sqlOngoingTransaction);
I had this error in a symfony 4 project. It was due to a conflict with dama/doctrine-test-bundle
Error disappeared after removing extension in phpunit config :

Trying to get property of non-object on codeigniter when check data

I would like to show data from database with "where" condition, how to show data in controller, the error show is "Trying to get property of non-object"
here is my controller :
$checkpassword = $this->m_user->checkpassword($oldpassword);
if($this->input->post('oldpassword') != $checkpassword->password)
{
$data['inputerror'][] = 'oldpassword';
$data['error_string'][] = 'your old password is wrong';
$data['status'] = FALSE;
}
and here is my model :
function checkpassword($oldpassword)
{
$this->db->where('password',$oldpassword);
return $this->db->get($this->table)->row();
}
When you perform row() or result() (any type of result object) and you get no results e.g. empty array or stdClass object you cannot access any of the properties because it is empty. That is why it is critical to build in num_rows().
function checkpassword($oldpassword)
{
$this->db->where('password',$oldpassword);
$query = $this->db->get($this->table)
if ($query->num_rows() > 0) {
return $query->row();
} else {
return null;
}
}
Usage:
if (is_null($checkpassword) || $this->input->post('oldpassword') != $checkpassword->password) { ... }
Now I have two problems with your code:
It appears that you are storing plaintext passwords (a big no no)
You check the password on the basis of the entire user table as per a comment you stated above but it is still possible that two users have the same password and thus you should also include a $this->db->where('username', $this->input->post('username')) in you check password function.
Given these two remarks it seems like your understanding of authentication systems is rather rudimentary (I don't mean to say this to be rude), and maybe you should consider using a pre-built plugin like Ion Auth, I use it myself and can recommend it.

How to access SESSION of loggedInUser outside CakePHP 2.x

I need to know if a user is logged in and need to access at his infos outside CakePHP but on the same domain.
I've tried the following code
session_start();
session_name('CAKEPHP');
if(isset($_COOKIE['CAKEPHP'])){
session_id($_COOKIE['CAKEPHP']);
echo "isset<br/>";
var_dump($_SESSION);
}
echo "user :".$_SESSION['userCakeUser']['email'];
I have the follwing output :
isset
array(1) {
["userCakeUser"]=> object(__PHP_Incomplete_Class)#1 (7)
{ ["__PHP_Incomplete_Class_Name"]=> string(12) "loggedInUser"
["email"]=> string(17) "a#a.net"<
["hash_pw"]=> string(65) "dsfsdfsdfsdfsdfsdfddsfsdfsdfsdf"
["user_id"]=> int(4) ["title"]=> string(10) "New Member"
["displayname"]=> string(5) "Toto"
["username"]=> string(5) "Toto"
}
}
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array on line 15
Please can you tell me how do I access the email for example.
The error message is giving you enough information about what is wrong:
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array on line 15
It's an object what you are dealing with. Try:
echo "user :".$_SESSION['userCakeUser']->email;
Thank you #Inigo Flores,
It is better, but I had the following error :
Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "loggedInUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition on line 16`
So I have Included this class :
include("path_to_cake_php/models/class.user.php" )

Resources