Note that there are some explanatory texts on larger screens.

plurals
  1. POphp query execution error when used as method
    primarykey
    data
    text
    <p>In my opinion i have a weird problem. The part below works fine</p> <pre><code> $sql = " UPDATE ".$table[0]." SET p_title = '".$_POST['p_title']."', p_date = '".$_POST['p_date']."' WHERE p_id = '".$_POST['p_id']."' "; if(!$db->exec($sql)){ echo($defaults->throwError('MySql error',$sql,implode(":",$db->errorInfo()))); }else{ $defaults->writeLog($table,$db->lastInsertId(),'update'); } </code></pre> <p>But when i try the code below i get an 'Fatal error: Call to a member function exec() on a non-object in'</p> <pre><code> class Defaults{ [..] public function query($sql){ if(!$db->exec($sql)){ echo($defaults->throwError('MySql error',$sql,implode(":",$db->errorInfo()))); }else{ $defaults->writeLog($table,$db->lastInsertId(),'update'); } } [..] } </code></pre> <p>and then on my page</p> <pre><code> $defaults = new Defaults(); $defaults->query(" UPDATE ".$table[0]." SET p_title = '".$_POST['p_title']."', p_date = '".$_POST['p_date']."' WHERE p_id = '".$_POST['p_id']."' "); </code> </pre> <p>How come?</p> <p> Ah, it was about the <code>$db</code> in the class. However, when i do something like</p> <pre><code> public function query($sql){ $db = new PDO($dbdata->hostname,$dbdata->username,$dbdata->password); if(!$db->exec($sql)){ echo($defaults->throwError('MySql error',$sql,implode(":",$db->errorInfo()))); }else{ $defaults->writeLog($table,$db->lastInsertId(),'update'); } } </code></pre> <p>I get a nasty</p> <pre> Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in /class.defaults.php:8 Stack trace: #0 /class.defaults.php(8): PDO->__construct('', NULL, NULL) #1 /class.form.php(269): Defaults->query('?????????UPDATE...') #2 /module.projectbeheer.edit.php(25): Form->proceed('update', 'p_id', 'rows', Array, Array, '') #3 /class.content.php(16): include_once('/path/') #4 /administratie.php(72): Content->write('/BraamsArchief/...') #5 {main} thrown in /class.defaults.php on line 8 </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload