Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:在中调用未定义的函数UNIX_TIMESTAMP()/_Php_Mysql_Pdo - Fatal编程技术网

Php 致命错误:在中调用未定义的函数UNIX_TIMESTAMP()/

Php 致命错误:在中调用未定义的函数UNIX_TIMESTAMP()/,php,mysql,pdo,Php,Mysql,Pdo,我正在尝试将我的数据库从MySQL更改为PDO。这很难,而且必须解决很多错误 我不知道如何解决这个错误 致命错误:调用/中未定义的函数UNIX_TIMESTAMP()。。。第63行 这是有错误的部分 function create_album($album_name, $album_description) { global $database; $database->query("INSERT INTO albums(album_id, id, timestamp, na

我正在尝试将我的数据库从MySQL更改为PDO。这很难,而且必须解决很多错误

我不知道如何解决这个错误

致命错误:调用/中未定义的函数UNIX_TIMESTAMP()。。。第63行

这是有错误的部分

function create_album($album_name, $album_description) {
    global $database;
    $database->query("INSERT INTO albums(album_id, id, timestamp, name, description)
        VALUES (':album_id', '".$_SESSION['id']."', 
        UNIX_TIMESTAMP(), ':album_name', ':album_description')", array('$_SESSION[id]' => ':session_id',
        ':timestamp' => UNIX_TIMESTAMP(), ':album_name' => $album_name, ':album_description' => $album_description));//this is line 63 

    mkdir('uploads/'.$album_name, 0744);
    mkdir('uploads/thumbs/'.$album_name, 0744);
}
为什么会出现致命错误,我在这里是否使用了
unix\u时间戳
错误?我怎样才能解决这个问题呢

谢谢。

UNIX\u TIMESTAMP()
不是PHP函数。此外,您的SQL中已经有了它,并且SQL字符串中没有
:timestamp
参数。因此,只要丢失
':timestamp'=>UNIX\u timestamp()
,您就应该很好了

此外,您的会话id部分也出现了问题。首先将会话id直接转储到SQL字符串中,然后将其添加到参数数组中,但值和键是相反的。

UNIX\u TIMESTAMP()
不是PHP函数。此外,您的SQL中已经有了它,并且SQL字符串中没有
:timestamp
参数。因此,只要丢失
':timestamp'=>UNIX\u timestamp()
,您就应该很好了


此外,您的会话id部分也出现了问题。首先,将会话id直接转储到SQL字符串中,然后将其添加到参数数组中,但值和键是相反的。

UNIX\u TIMESTAMP
是一个MySQL函数,而不是PHP函数。您不需要将参数绑定到
UNIX\u TIMESTAMP
,只需在查询中使用它即可


摆脱
':timestamp'=>UNIX\u timestamp()
,这是您的问题。首先,
UNIX\u TIMESTAMP
不是一个PHP函数,而
:TIMESTAMP
在查询中不存在

另外,
”:session_id“
应该是键

更新:您需要使用
prepare
/
execute
而不是
query
来运行准备好的语句

$stmt = $database->prepare("INSERT INTO albums(id, timestamp, name, description) VALUES (':session_id', UNIX_TIMESTAMP(), ':album_name', ':album_description')");
$stmt->execute(array(
    ':session_id' => $_SESSION[id],
    ':album_name' => $album_name,
    ':album_description' => $album_description
));

我假设相册id是自动递增的。如果没有,您应该将其添加到查询中。

UNIX\u TIMESTAMP
是MySQL函数,而不是PHP函数。您不需要将参数绑定到
UNIX\u TIMESTAMP
,只需在查询中使用它即可


摆脱
':timestamp'=>UNIX\u timestamp()
,这是您的问题。首先,
UNIX\u TIMESTAMP
不是一个PHP函数,而
:TIMESTAMP
在查询中不存在

另外,
”:session_id“
应该是键

更新:您需要使用
prepare
/
execute
而不是
query
来运行准备好的语句

$stmt = $database->prepare("INSERT INTO albums(id, timestamp, name, description) VALUES (':session_id', UNIX_TIMESTAMP(), ':album_name', ':album_description')");
$stmt->execute(array(
    ':session_id' => $_SESSION[id],
    ':album_name' => $album_name,
    ':album_description' => $album_description
));
我假设相册id是自动递增的。如果不是,则应将其添加到查询中。

UNIX\u TIMESTAMP()不是PHP函数,而是来自MYSQL。而是使用time()

UNIX\u TIMESTAMP()不是PHP函数,而是来自MYSQL。而是使用时间()

火箭危险品, 数据库来自member.php

require_once('config.inc.php');
require_once("database.class.php");
require_once("member.class.php");
require("album.func.php");
require("image.func.php");
require("thumb.func.php");
/* Start an instance of the Database Class */
$database = new database("xxx", "xxx", "xxx", "xxx");
/* Create an instance of the Member Class */
$member = new member();
database.class.php是

类数据库{

public $pdo = null;


public $statement = null;


 * Database Constructor
 * 
 * This method is used to create a new database object with a connection to a datbase
 */
public function __construct() {
    /* Try the connections */
    try {
        /* Create a connections with the supplied values */
        $this->pdo = new PDO("mysql:host=" . Config::read('hostname') . ";dbname=" . Config::read('database') . "", Config::read('username'), Config::read('password'), Config::read('drivers'));


/*
 * Database Query
 * 
 * This method is used to create a new database prepared query
 * 
 * @param string $query The prepared statement query to the database
 * @param array|string $bind All the variables to bind to the prepared statement
 * @return return the executed string
 */
public function query($query, $bind = null, $fetch = 'FETCH_ASSOC') {
    /* Prepare the query statement */
    $this->statement = $this->pdo->prepare($query);
    /* Bind each value supplied from $bind */
    if($bind != null) {
        foreach($bind as $select => $value) {
            /* For each type of value give the appropriate param */
            if(is_int($value)) {
                $param = PDO::PARAM_INT; 
            } elseif(is_bool($value)) {
                $param = PDO::PARAM_BOOL;
            } elseif(is_null($value)) {
                $param = PDO::PARAM_NULL;
            } elseif(is_string($value)) {
                $param = PDO::PARAM_STR;
            } else {
                $param = FALSE;
            }
            /* Bid value */
            if($param) {
                $this->statement->bindValue($select, $value, $param);
            }
        }
    }
    /* Execute Query & check for any errors */
    if(!$this->statement->execute()){
        $result = array(
            1 => 'false',
            2 => '<b>[DATABASE] Error - Query:</b> There was an error in sql syntax',
        );
        return $result;
    }
    /* Return all content */
    if($fetch == 'FETCH_ASSOC') {
        $result = $this->statement->fetch(PDO::FETCH_ASSOC);
    } elseif($fetch == 'FETCH_BOTH') {
        $result = $this->statement->fetch(PDO::FETCH_BOTH);
    } elseif($fetch == 'FETCH_LAZY') {
        $result = $this->statement->fetch(PDO::FETCH_LAZY);
    } elseif($fetch == 'FETCH_OBJ') {
        $result = $this->statement->fetch(PDO::FETCH_OBJ);
    } elseif($fetch == 'fetchAll') {
        $result = $this->statement->fetchAll();
    }
    return $result;
}
public$pdo=null;
public$statement=null;
*数据库构造函数
* 
*此方法用于创建一个连接到数据库的新数据库对象
*/
公共函数构造(){
/*尝试连接*/
试一试{
/*使用提供的值创建连接*/
$this->pdo=new-pdo(“mysql:host=”.Config::read('hostname')。“dbname=”.Config::read('database')。”,Config::read('username'),Config::read('password'),Config::read('drivers'));
/*
*数据库查询
* 
*此方法用于创建新的数据库准备查询
* 
*@param string$query将准备好的语句查询到数据库
*@param array | string$绑定所有要绑定到准备语句的变量
*@return返回执行的字符串
*/
公共函数查询($query,$bind=null,$fetch='fetch\u ASSOC'){
/*准备查询语句*/
$this->statement=$this->pdo->prepare($query);
/*绑定$Bind提供的每个值*/
如果($bind!=null){
foreach($bind as$select=>$value){
/*对于每种类型的值,给出相应的参数*/
如果(是整($value)){
$param=PDO::param_INT;
}elseif(is_bool($value)){
$param=PDO::param_BOOL;
}elseif(为空($value)){
$param=PDO::param_NULL;
}elseif(is_字符串($value)){
$param=PDO::param_STR;
}否则{
$param=FALSE;
}
/*投标价值*/
如果($param){
$this->statement->bindValue($select,$value,$param);
}
}
}
/*执行查询并检查是否有任何错误*/
如果(!$this->statement->execute()){
$result=数组(
1=>“假”,
2=>“[数据库]错误-查询:sql语法中有错误”,
);
返回$result;
}
/*返回所有内容*/
如果($fetch=='fetch\u ASSOC'){
$result=$this->statement->fetch(PDO::fetch_ASSOC);
}elseif($fetch=='fetch\u BOTH'){
$result=$this->statement->fetch(PDO::fetch_两者);
}elseif($fetch==“fetch\u LAZY”){
$result=$this->statement->fetch(PDO::fetch\u LAZY);
}elseif($fetch=='fetch_OBJ'){
$result=$this->statement->fetch(PDO::fetch_OBJ);
}elseif($fetch==“fetchAll”){
$result=$this->statement->fetchAll();
}
返回$result;
}
}火箭危险品, 数据库来自member.php

require_once('config.inc.php');
require_once("database.class.php");
require_once("member.class.php");
require("album.func.php");
require("image.func.php");
require("thumb.func.php");
/* Start an instance of the Database Class */
$database = new database("xxx", "xxx", "xxx", "xxx");
/* Create an instance of the Member Class */
$member = new member();
database.class.php是

类数据库{

public $pdo = null;


public $statement = null;


 * Database Constructor
 * 
 * This method is used to create a new database object with a connection to a datbase
 */
public function __construct() {
    /* Try the connections */
    try {
        /* Create a connections with the supplied values */
        $this->pdo = new PDO("mysql:host=" . Config::read('hostname') . ";dbname=" . Config::read('database') . "", Config::read('username'), Config::read('password'), Config::read('drivers'));


/*
 * Database Query
 * 
 * This method is used to create a new database prepared query
 * 
 * @param string $query The prepared statement query to the database
 * @param array|string $bind All the variables to bind to the prepared statement
 * @return return the executed string
 */
public function query($query, $bind = null, $fetch = 'FETCH_ASSOC') {
    /* Prepare the query statement */
    $this->statement = $this->pdo->prepare($query);
    /* Bind each value supplied from $bind */
    if($bind != null) {
        foreach($bind as $select => $value) {
            /* For each type of value give the appropriate param */
            if(is_int($value)) {
                $param = PDO::PARAM_INT; 
            } elseif(is_bool($value)) {
                $param = PDO::PARAM_BOOL;
            } elseif(is_null($value)) {
                $param = PDO::PARAM_NULL;
            } elseif(is_string($value)) {
                $param = PDO::PARAM_STR;
            } else {
                $param = FALSE;
            }
            /* Bid value */
            if($param) {
                $this->statement->bindValue($select, $value, $param);
            }
        }
    }
    /* Execute Query & check for any errors */
    if(!$this->statement->execute()){
        $result = array(
            1 => 'false',
            2 => '<b>[DATABASE] Error - Query:</b> There was an error in sql syntax',
        );
        return $result;
    }
    /* Return all content */
    if($fetch == 'FETCH_ASSOC') {
        $result = $this->statement->fetch(PDO::FETCH_ASSOC);
    } elseif($fetch == 'FETCH_BOTH') {
        $result = $this->statement->fetch(PDO::FETCH_BOTH);
    } elseif($fetch == 'FETCH_LAZY') {
        $result = $this->statement->fetch(PDO::FETCH_LAZY);
    } elseif($fetch == 'FETCH_OBJ') {
        $result = $this->statement->fetch(PDO::FETCH_OBJ);
    } elseif($fetch == 'fetchAll') {
        $result = $this->statement->fetchAll();
    }
    return $result;
}
public$pdo=null;
public$statement=null;
*数据库构造函数
* 
*此方法用于创建一个连接到数据库的新数据库对象
*/
公共函数构造(){
/*尝试连接*/
试一试{
/*使用提供的值创建连接*/
$this->pdo=new-pdo(“mysql:host=”.Config::read('hostname')。“dbname=”.Config::read('database'))