mysqli函数和外部类

时间:2014-02-06 19:53:14

标签: php function mysqli

我试图编写一个使用外部数据库类的函数,但它不太顺利。当它不在函数中时,该类工作正常。继承我的代码:

require_once('MysqliDb.php');


function add_post($userid,$body,$cat_id,$user_link){ 

$db = new MysqliDb('localhost', 'root', 'root', 'my_database');

$date = new DateTime();
$now = $date->getTimestamp();

$insertData = array(
   'user_id' => $userid,
    'body' => $body,
    'stamp' => $now,
    'cat_id' => $cat_id,
    'link' => $user_link
);

if ( $Db->insert('posts', $insertData) ) echo 'success!';


}

接下来的电话:

$userid = 1;
$body = "hey whats up this is from a db class";
$cat_id = 3;
$user_link = "http://www.aol.com";
add_post($userid,$body,$cat_id,$user_link);

0 个答案:

没有答案