Mysqli exception in Codeigniter












0














Trying to set up a project in Codeigniter I am having:




PHP Fatal error: Uncaught exception 'Exception' with message
'missing: mysqli_real_escape_string or bad connection ID' in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php:341nStack
trace:n#0 /var/www/public/system/database/DB_driver.php(742):
CI_DB_mysqli_driver->escape_str('192.168.33.1')n#1
/var/www/public/system/database/DB_active_rec.php(427):
CI_DB_driver->escape('192.168.33.1')n#2
/var/www/public/system/database/DB_active_rec.php(366):
CI_DB_active_record->_where('addr', '192.168.33.1', 'AND ', true)n#3
/var/www/public/application/classes/model.php(451):
CI_DB_active_record->where('addr', '192.168.33.1')n#4
/var/www/public/application/classes/model.php(495):
Model::find_id('192.168.33.1', '*')n#5
/var/www/public/application/classes/model.php(480):
Model::find_sub('192.168.33.1', NULL)n#6
/var/www/public/application/core/CIL_Controller.php(981):
Model::find('192.168.33.1')n#7
/var/www/public/application/core/CIL_Controller.php(104):
CIL_Controller->check_blocked()n#8
/var/www/public/system/core/Controller in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php on
line 341




I cannot figure out why



The part of the code that generate the error is:



if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
else
{
throw new Exception('missing: mysqli_real_escape_string or bad connection ID');
}









share|improve this question
























  • People still escaping strings in 2018. Why not using something much more secured like php.net/manual/en/mysqli.prepare.php ?
    – Alon Eitan
    Nov 11 at 17:37










  • If you're using Codeigniter why not taking advantage of it, save some lines of code and let it handle that on its own?
    – Javier Larroulet
    Nov 11 at 18:23










  • Based on the stack trace it seems you are using a really old and obsolete version of CodeIgniter. You should consider updating.
    – DFriend
    Nov 12 at 4:52
















0














Trying to set up a project in Codeigniter I am having:




PHP Fatal error: Uncaught exception 'Exception' with message
'missing: mysqli_real_escape_string or bad connection ID' in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php:341nStack
trace:n#0 /var/www/public/system/database/DB_driver.php(742):
CI_DB_mysqli_driver->escape_str('192.168.33.1')n#1
/var/www/public/system/database/DB_active_rec.php(427):
CI_DB_driver->escape('192.168.33.1')n#2
/var/www/public/system/database/DB_active_rec.php(366):
CI_DB_active_record->_where('addr', '192.168.33.1', 'AND ', true)n#3
/var/www/public/application/classes/model.php(451):
CI_DB_active_record->where('addr', '192.168.33.1')n#4
/var/www/public/application/classes/model.php(495):
Model::find_id('192.168.33.1', '*')n#5
/var/www/public/application/classes/model.php(480):
Model::find_sub('192.168.33.1', NULL)n#6
/var/www/public/application/core/CIL_Controller.php(981):
Model::find('192.168.33.1')n#7
/var/www/public/application/core/CIL_Controller.php(104):
CIL_Controller->check_blocked()n#8
/var/www/public/system/core/Controller in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php on
line 341




I cannot figure out why



The part of the code that generate the error is:



if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
else
{
throw new Exception('missing: mysqli_real_escape_string or bad connection ID');
}









share|improve this question
























  • People still escaping strings in 2018. Why not using something much more secured like php.net/manual/en/mysqli.prepare.php ?
    – Alon Eitan
    Nov 11 at 17:37










  • If you're using Codeigniter why not taking advantage of it, save some lines of code and let it handle that on its own?
    – Javier Larroulet
    Nov 11 at 18:23










  • Based on the stack trace it seems you are using a really old and obsolete version of CodeIgniter. You should consider updating.
    – DFriend
    Nov 12 at 4:52














0












0








0







Trying to set up a project in Codeigniter I am having:




PHP Fatal error: Uncaught exception 'Exception' with message
'missing: mysqli_real_escape_string or bad connection ID' in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php:341nStack
trace:n#0 /var/www/public/system/database/DB_driver.php(742):
CI_DB_mysqli_driver->escape_str('192.168.33.1')n#1
/var/www/public/system/database/DB_active_rec.php(427):
CI_DB_driver->escape('192.168.33.1')n#2
/var/www/public/system/database/DB_active_rec.php(366):
CI_DB_active_record->_where('addr', '192.168.33.1', 'AND ', true)n#3
/var/www/public/application/classes/model.php(451):
CI_DB_active_record->where('addr', '192.168.33.1')n#4
/var/www/public/application/classes/model.php(495):
Model::find_id('192.168.33.1', '*')n#5
/var/www/public/application/classes/model.php(480):
Model::find_sub('192.168.33.1', NULL)n#6
/var/www/public/application/core/CIL_Controller.php(981):
Model::find('192.168.33.1')n#7
/var/www/public/application/core/CIL_Controller.php(104):
CIL_Controller->check_blocked()n#8
/var/www/public/system/core/Controller in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php on
line 341




I cannot figure out why



The part of the code that generate the error is:



if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
else
{
throw new Exception('missing: mysqli_real_escape_string or bad connection ID');
}









share|improve this question















Trying to set up a project in Codeigniter I am having:




PHP Fatal error: Uncaught exception 'Exception' with message
'missing: mysqli_real_escape_string or bad connection ID' in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php:341nStack
trace:n#0 /var/www/public/system/database/DB_driver.php(742):
CI_DB_mysqli_driver->escape_str('192.168.33.1')n#1
/var/www/public/system/database/DB_active_rec.php(427):
CI_DB_driver->escape('192.168.33.1')n#2
/var/www/public/system/database/DB_active_rec.php(366):
CI_DB_active_record->_where('addr', '192.168.33.1', 'AND ', true)n#3
/var/www/public/application/classes/model.php(451):
CI_DB_active_record->where('addr', '192.168.33.1')n#4
/var/www/public/application/classes/model.php(495):
Model::find_id('192.168.33.1', '*')n#5
/var/www/public/application/classes/model.php(480):
Model::find_sub('192.168.33.1', NULL)n#6
/var/www/public/application/core/CIL_Controller.php(981):
Model::find('192.168.33.1')n#7
/var/www/public/application/core/CIL_Controller.php(104):
CIL_Controller->check_blocked()n#8
/var/www/public/system/core/Controller in
/var/www/public/system/database/drivers/mysqli/mysqli_driver.php on
line 341




I cannot figure out why



The part of the code that generate the error is:



if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
else
{
throw new Exception('missing: mysqli_real_escape_string or bad connection ID');
}






php codeigniter mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 17:39









Alon Eitan

11.1k63652




11.1k63652










asked Nov 11 at 17:21









VladimirCoder84

184




184












  • People still escaping strings in 2018. Why not using something much more secured like php.net/manual/en/mysqli.prepare.php ?
    – Alon Eitan
    Nov 11 at 17:37










  • If you're using Codeigniter why not taking advantage of it, save some lines of code and let it handle that on its own?
    – Javier Larroulet
    Nov 11 at 18:23










  • Based on the stack trace it seems you are using a really old and obsolete version of CodeIgniter. You should consider updating.
    – DFriend
    Nov 12 at 4:52


















  • People still escaping strings in 2018. Why not using something much more secured like php.net/manual/en/mysqli.prepare.php ?
    – Alon Eitan
    Nov 11 at 17:37










  • If you're using Codeigniter why not taking advantage of it, save some lines of code and let it handle that on its own?
    – Javier Larroulet
    Nov 11 at 18:23










  • Based on the stack trace it seems you are using a really old and obsolete version of CodeIgniter. You should consider updating.
    – DFriend
    Nov 12 at 4:52
















People still escaping strings in 2018. Why not using something much more secured like php.net/manual/en/mysqli.prepare.php ?
– Alon Eitan
Nov 11 at 17:37




People still escaping strings in 2018. Why not using something much more secured like php.net/manual/en/mysqli.prepare.php ?
– Alon Eitan
Nov 11 at 17:37












If you're using Codeigniter why not taking advantage of it, save some lines of code and let it handle that on its own?
– Javier Larroulet
Nov 11 at 18:23




If you're using Codeigniter why not taking advantage of it, save some lines of code and let it handle that on its own?
– Javier Larroulet
Nov 11 at 18:23












Based on the stack trace it seems you are using a really old and obsolete version of CodeIgniter. You should consider updating.
– DFriend
Nov 12 at 4:52




Based on the stack trace it seems you are using a really old and obsolete version of CodeIgniter. You should consider updating.
– DFriend
Nov 12 at 4:52












1 Answer
1






active

oldest

votes


















0















Caution Security: the default character set The character set must be
set either at the server level, or with the API function
mysqli_set_charset() for it to affect mysqli_real_escape_string(). See
the concepts section on character sets for more information.




Or check if there are any errors when trying to connect



$mysqli = @new mysqli('localhost', 'user', 'my_password', 'my_db');

if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}


And if all ok do this



$str= $mysqli->real_escape_string($str)





share|improve this answer























  • In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
    – DFriend
    Nov 12 at 4:58











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251261%2fmysqli-exception-in-codeigniter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















Caution Security: the default character set The character set must be
set either at the server level, or with the API function
mysqli_set_charset() for it to affect mysqli_real_escape_string(). See
the concepts section on character sets for more information.




Or check if there are any errors when trying to connect



$mysqli = @new mysqli('localhost', 'user', 'my_password', 'my_db');

if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}


And if all ok do this



$str= $mysqli->real_escape_string($str)





share|improve this answer























  • In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
    – DFriend
    Nov 12 at 4:58
















0















Caution Security: the default character set The character set must be
set either at the server level, or with the API function
mysqli_set_charset() for it to affect mysqli_real_escape_string(). See
the concepts section on character sets for more information.




Or check if there are any errors when trying to connect



$mysqli = @new mysqli('localhost', 'user', 'my_password', 'my_db');

if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}


And if all ok do this



$str= $mysqli->real_escape_string($str)





share|improve this answer























  • In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
    – DFriend
    Nov 12 at 4:58














0












0








0







Caution Security: the default character set The character set must be
set either at the server level, or with the API function
mysqli_set_charset() for it to affect mysqli_real_escape_string(). See
the concepts section on character sets for more information.




Or check if there are any errors when trying to connect



$mysqli = @new mysqli('localhost', 'user', 'my_password', 'my_db');

if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}


And if all ok do this



$str= $mysqli->real_escape_string($str)





share|improve this answer















Caution Security: the default character set The character set must be
set either at the server level, or with the API function
mysqli_set_charset() for it to affect mysqli_real_escape_string(). See
the concepts section on character sets for more information.




Or check if there are any errors when trying to connect



$mysqli = @new mysqli('localhost', 'user', 'my_password', 'my_db');

if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}


And if all ok do this



$str= $mysqli->real_escape_string($str)






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 11:40

























answered Nov 11 at 17:47









Yaroslaw

684




684












  • In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
    – DFriend
    Nov 12 at 4:58


















  • In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
    – DFriend
    Nov 12 at 4:58
















In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
– DFriend
Nov 12 at 4:58




In CodeIgniter the value of $this->conn_id is same thing as is returned by new mysqli(...
– DFriend
Nov 12 at 4:58


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251261%2fmysqli-exception-in-codeigniter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini