Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch_field() on a non-object #6

Closed
okpg opened this issue Dec 11, 2012 · 2 comments
Closed

fetch_field() on a non-object #6

okpg opened this issue Dec 11, 2012 · 2 comments

Comments

@okpg
Copy link

okpg commented Dec 11, 2012

not sure if this is a bug or just me. INSERTS row just fine but shows the following errors running $params individually. I can understand, I think?, the class iterates over the elements so params1 and params2 look the same but what's fetch_field() doing?

$params = array('first'=>'me1', 'last'=>'him1', 'user'=>'21', 'zoneId'=>'1');

    Fatal error: Call to a member function fetch_field() on a non-object in  on line 405
    Call Stack
    #   Time    Memory  Function    Location
    1   0.0007  372968  {main}( )   ..\new16.php:0
    2   0.0079  485912  Database->rawQuery( )   ..\new16.php:26
    3   0.4641  492328  Database->_dynamicBindResults( )    ..\c_Database.php:119

$params = array('joe', 'blow', '3', '1');

    Fatal error: Call to a member function fetch_field() on a non-object in  line 405
    Call Stack
    #   Time    Memory  Function    Location
    1   0.0007  372888  {main}( )   ..\new16.php:0
    2   0.0052  485792  Database->rawQuery( )   ..\new16.php:31
    3   0.0076  492184  Database->_dynamicBindResults( )    ..\c_Database.php:119

$db = new Database('localhost', 'user', 'password', 'test');

$sql ="INSERT INTO x_user (first, last, user, zoneId) VALUES (?, ?, ?, ?)";

$result = $db->rawQuery($sql, $params);

@irfannaseefp
Copy link

You can use insert function for this.

$insertdata = array('first'=>'me1', 'last'=>'him1', 'user'=>'21', 'zoneId'=>'1');
if($result = $db->insert('x_user') ) echo "Succes";

Actually this issue you are facing is because , in rawQuery function, they are sanitizing the query using filter_var function.

@irfannaseefp
Copy link

As a quick way out , you can go to Class MysqliDB and edit the rawQuery function definition first line as follows:

public function rawQuery($query, $bindParams = NULL)
{
// $this->_query = filter_var($query, FILTER_SANITIZE_STRING);
$this->_query = $this->_mysqli->real_escape_string($query);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants