'Zend_Db_Statement_Exception' with message 'Invalid bind-variable name ':1' - php

Good day,
Background Info:
Client's hosting server is being upgraded from PHP 5.2 to PHP 5.3. The client's app breaks when tested on PHP 5.3. Specifically the insert and update methods are the ones which are breaking the app. The app coded in Zend Framework v1.7.2.
We have tried simply upgrading the Zend Framework core, however it seems that the previous developers made changes to the core, which causes the app to completely break when the framework has been upgraded.
Problem
The best solution was to add a class called AppModel which extends Zend_Db_Table_Abstract and then simply overwrite the insert and update methods. All models in this app extend the AppModel class. This works fine until checkbox data or radio button data has to be written to the database.
The app now throws the following error:
Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with
message 'Invalid bind-variable name ':1'' in ....
NB. Full error message at the bottom
I have been looking for a solution on the internet for days in vain. One of the solutions I found was to change Mysqli to Pdo_Mysql. however it seems that there is no such class in the framework. There is the class Pdo which throws the same error as Mysqli.
Please help!
Please excuse my English. If you need clarification please dont hesitate to contact me. thanks in advance
The following is code sample from the AppModel class:
class AppModel extends Zend_Db_Table_Abstract{
//PHP 5.3 fix
public function insert(array $data) {
//array to carry data for holding data
$ins_data = array();
foreach($data as $table => $value){
$ins_data['tables'][] = $table;
$ins_data['values'][] = mysql_escape_string($value);
}
$db = Zend_Registry::get('db');
$ins_query = ' INSERT INTO '. $this->_name.' ('.implode($ins_data['tables'], ', ').')
VALUES ("'.implode($ins_data['values'], '", "').'")';
$ins_action = new Zend_Db_Statement_Mysqli($db, $ins_query);
$ins_action->execute();
return $db->lastInsertId();
}
}
Complete error message:
Fatal error:
Uncaught exception 'Zend_Db_Statement_Exception'
with message 'Invalid bind-variable name ':1''
in C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php:143
Stack trace:
#0 C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php(108): Zend_Db_Statement->_parseParameters(' UPDATE user_te...')
#1 C:\wamp\www\schoolnet\application\AppModel.php(43): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), ' UPDATE user_te...')
#2 C:\wamp\www\schoolnet\application\modules\user\helpers\UserHelper.php(530): AppModel->update(Array, 'user_id = 6')
#3 C:\wamp\www\schoolnet\application\modules\user\controllers\UserController.php(533): user_helpers_UserHelper->teacherUpdate(Array, 6)
#4 C:\wamp\www\schoolnet\application\modules\user\controllers\UserController.php(300): UserController->teacherUpdateDetails(Array, 6)
#5 C:\wamp\www\schoolnet\public_html\Zend\Controller\Action.php(503): UserController->detailseditAction()
#6 C:\wamp\www\schoolnet\public_html\Zend\Controller\Dispatcher\Standard.php(285): Zend_Control in C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php on line 143

Related

MongoDB insertOne function not found

I'm trying to use MONGODB in my project and I just started using it when it has this problem. I created another directory and ran the files with no problems whatsoever. What is wrong with this? I keep getting Fatal error: Uncaught Error: Call to undefined method MongoDB\Database::insertOne() error message.
This is my code to the class called Database which is producing the error.
<?php
namespace auth;
include_once dirname(__DIR__) . "/config.php";
class Database
{
public function __construct(
private readonly string $dbname,
){
$this->run();
}
private function run(): void
{
$collection = (new \MongoDB\Client)->{$this->dbname};
$insertOneResult = $collection->insertOne([
'username' => 'admin',
'email' => 'admin#example.com',
'name' => 'Admin User',
]);
printf("Inserted %d document(s)\n", $insertOneResult->getInsertedCount());
var_dump($insertOneResult->getInsertedId());
}
}
and my test.php file just contained some lines of code
include_once "./assets/php/config.php";
$database = new \auth\Database("test->users");
I definitely loaded the class MongoDB and my config.php includes the vendor file of composer's.
This is the error in full.
Fatal error: Uncaught Error: Call to undefined method MongoDB\Database::insertOne() in C:\xampp\htdocs\PP\assets\php\Classes\Database.php:18
Stack trace:
#0 C:\xampp\htdocs\PP\assets\php\Classes\Database.php(11): auth\Database->run()
#1 C:\xampp\htdocs\PP\test.php(15): auth\Database->__construct('test->users')
#2 {main}
thrown in C:\xampp\htdocs\PP\assets\php\Classes\Database.php on line 18
PHP Fatal error: Uncaught Error: Call to undefined method MongoDB\Database::insertOne() in C:\xampp\htdocs\PPa\assets\php\Classes\Database.php:18
Stack trace:
#0 C:\xampp\htdocs\PP\assets\php\Classes\Database.php(11): auth\Database->run()
#1 C:\xampp\htdocs\PP\test.php(15): auth\Database->__construct('test->users')
#2 {main}
thrown in C:\xampp\htdocs\PP\assets\php\Classes\Database.php on line 18
Process finished with exit code 255
The config.phpfile that I have included
include_once dirname(__DIR__, 2) . "/vendor/autoload.php";
include_once "autoload.php";
Thanks for any help.
Ah yes answer to my question, I'm just well not thinking properly at the time of writing the code. The `MongoDB\Collection" class accepts two arguments from the user and one internally set. The user provided argument is the database name and collection name. Doing it with (new \MongoDB\Client)->{$this->dbname} is wrong because it provides just the database string and not the collection name.
I resolved this issue by changing how the structure looks of the collection. md is just the alias for MongoDB class as I do not want to type such a long string everytime.
$collection = (new md\Client)->$db->$collection_name;
However, I have no idea how mongoDB uses the db and collection_name as magic constants as I have looked through the entire MongoDB\Client file and found there is no code stating those "magic constants"? I would appreciate if someone has an answer to this.

Propel: Class 'Criteria' not found

I'm currently getting to know Propel, but I'm having a hard time getting this to work.
To give a bit of background I want to get the last row of my table 'Message' using Propel. To archieve this I want to use the class 'Criteria'.
My problem is that PHP cannot find the class Criteria when I the programm is executed. I know I have to import the class somehow but I don't know where it is located. Here's my Code:
<?php
session_start();
// setup the autoloading
require_once '/home/smalburg/propel/vendor/autoload.php';
// setup Propel
require_once '/home/smalburg/propel/generated-conf/config.php';
//Get id from last row in table
$row = MessageQuery::create()->
orderById(Criteria::DESC)->
limit(1)->
find();
?>
I have installed Propel using composer.
Here's the error message to whom it may concern (don't mind Line 17 i have shortend the code):
Fatal error: Uncaught Error: Class 'Criteria' not found in /var/www/html/propel/nachrichten_schicken.php:17 Stack trace: #0 {main} thrown in /var/www/html/propel/nachrichten_schicken.php on line 17
Please help me I refuse to go to bed before this is fixed.
Update:
I did go to bed.
First of all, PetrHejda's solution worked, but I also found an alternative way to solve my specific problem:
Instead of using orderById(\Propel\Runtime\ActiveQuery\Criteria::DESC)-> (like in Petr's solution) one can just say orderById('desc')->, which also worked fine. Thanks for the help!
Propel's class Criteria is in the namespace \Propel\Runtime\ActiveQuery.
Either prepend the namespace to the class name
orderById(\Propel\Runtime\ActiveQuery\Criteria::DESC)
or import it
use Propel\Runtime\ActiveQuery\Criteria;
orderById(Criteria::DESC)

Webtools and developer tools issue on Phalcon framework

I installed phalcon 3.0.1-14 on an Ubuntu 14.04 box. Also installed Phalcon DevTools (3.0.1).
Initially, I enabled the webtools and when I visit that page, some warnings appear all the time:
Cannot bind an instance to a static closure in /home/pish/vendor/phalcon/devtools/scripts/Phalcon/Web/Tools.php
Cannot bind an instance to a static closure in /home/pish/vendor/phalcon/devtools/scripts/Phalcon/Web/Tools/views/index.phtml
I just ignored them and tried to create a model out of an existing table in the database. When I clicked on "Generate" button
I get the following error:
Phalcon\Mvc\Dispatcher\Exception: ModelsController handler class cannot be loaded
and the model is not created. I tested creating a controller as well, but a similar error occurred and the controller
was not created either.
Finally, I created the model via the console phalcon model users and it was created successfully.
I noticed, though, that the validation function created by the developer tools doesn't work and causes the following
error when I try to create a user:
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\Email given in...
My question is basically, is there something bad with the version of developer tools I installed that causes the problems
with the Webtools and the functions that are generated for models/controllers, etc.? Or I might have something wrong
in my system?
Cannot bind an instance to a static closure
https://github.com/phalcon/cphalcon/issues/11029
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate()
Fixed in the 3.0.x branch (will be released soon)
Regarding your second error message:
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\Email given in...
Model validation has changed in Phalcon 3.0. In Phalcon v2 you had to do
public function validation()
{
$this->validate(
new Phalcon\Mvc\Model\Validator\Email(['field' => 'email']);
);
if ($this->validationHasFailed() == true) {
return false;
}
}
But the Phalcon\Mvc\Model\Validation is deprecated in v3 and you should use Phalcon\Validation instead. Just alter your code to the following:
public function validation()
{
$validator = new Validation();
$validator->add(
'email', //your field name
new Phalcon\Validation\Validator\Email([
'model' => $this,
'message' => 'Please enter a correct email address'
])
);
return $this->validate($validator);
}
Maybe the DevTools haven't updated this part yet, I am not sure.

Post Web Service in codeigniter using REST Server not working and showing error

I am new for codeigniter and I am using Phil Sturgeon’s REST server for "post" type of web service. althiugh my 'get' type web service is working perfectly. Below is my controller code for post web service.
require(APPPATH.'libraries/REST_Controller.php');
class json extends REST_Controller {
public function __construct() {
parent::__construct();
}
public function data_post() {
$user = array(
'id' => $params['id']
);
$this->response(array('status'=>'success'), 200);
}
}
and i amd using rest add on to check web services working or not but i am getting below error.
Fatal error: Uncaught exception 'Exception' with message 'Format class does not support conversion from "php".' in /home/magnetic/public_html/touch/order-form/application/libraries/Format.php:51 Stack trace: #0 /home/magnetic/public_html/touch/order-form/application/libraries/Format.php(31): Format->__construct('{"id": "restCli...', 'php') #1 /home/magnetic/public_html/touch/order-form/application/libraries/REST_Controller.php(247): Format->factory('{"id": "restCli...', 'php') #2 /home/magnetic/public_html/touch/order-form/application/controllers/json.php(6): REST_Controller->__construct() #3 /home/magnetic/public_html/touch/order-form/system/core/CodeIgniter.php(308): json->__construct() #4 /home/magnetic/public_html/touch/order-form/index.php(202): require_once('/home/magnetic/...') #5 {main} thrown in /home/magnetic/public_html/touch/order-form/application/libraries/Format.php on line 51
http://awesomescreenshot.com/0cd38frz01 is screenshot of rest addon error
Please let me know what else i need to do if anything remaining in my code and please let me know the whole process of using rest server for 'post' web services.
Thanks in advance
In the body of the RESTClient, try sending:
id=restClient%20Test
instead of
{"id": "restCliente Test"}

Ion Auth/CodeIgniter Fatal Error: Undefined method Ion_auth::get_user() called

Receiving this fatal error when trying to access my planner.php and shared.php controllers. Any thoughts?
Fatal error: Uncaught exception 'Exception' with message 'Undefined method Ion_auth::get_user() called' in
/application/libraries/Ion_auth.php:88 Stack trace: #0
/application/core/MY_Controller.php(50): Ion_auth->__call('get_user', Array) #1
/application/core/MY_Controller.php(50): Ion_auth->get_user() #2
/application/controllers/user/planner.php(9): Common_Auth_Controller->__construct() #3
/system/core/CodeIgniter.php(288): Planner->__construct() #4 /index.php(202): require_once('/Users/lrussell...') #5 {main} thrown in/application/libraries/Ion_auth.php on line 88
Library Extension I'm Using for Ion Auth:
http://jondavidjohn.com/blog/2011/01/scalable-login-system-for-codeigniter-ion_auth
Planner Controller:
http://pastie.org/private/wc1bq6eiqb9hn8iubwdgq
Shared Controller:
http://pastie.org/private/uj3ta8dw3jl7kqxizs9n1a
Ion_auth Library Line 88 Segment:
http://pastie.org/private/mhgwdzjyhatwsdrux4gqpa
CRUD Model:
http://pastie.org/private/m2nhfqzabdsx5eiz6xqupw
Events Model:
http://pastie.org/private/b6ksjoowl7wde9errow
Shared Model:
http://pastie.org/private/f741jfnf8o2l5oxphnrl5w
Uhm, it happened to me the same exact thing. In the latest releases of this library, Ben Edmunds used php magic method __call() so that you don't have to call a model's method by using the regular syntax $this->ion_auth_model->method() but using instead $this->ion_auth->method(), as if it was a method belonging to the library.
But, actually, that method belongs to the model. So, if you go have a look at the model, you'll see that there's no get_user() method (nor is there in the library!), or at least in the version I talk about (the latest or the one just before. I downloaded a fresh copy one or two weeks ago).
I think there are some errors in the documentation he provided (though the overall work he did is awesome, kudos to Ben).
You can try using the user() model method, which should yield to the same result (it's the closer in functionality). So call $this->ion_auth->user() and see if that fits your needs.
EDIT
To clarify... instead of this...
$this->end_user = $this->ion_auth->current()->row();
do this...
$this->end_user = $this->ion_auth->user()->row();

Categories