不要通过PHP查询在ubuntu中创建数据库

时间:2015-03-20 08:43:11

标签: php database ubuntu

<code>
require 'INewsDB.class.php';
class NewsDB implements INewsDB{
protected  $_db;
const DB_NAME = '/var/www/mysite/news.db';
/**
 *
 */
function __construct(){
    if(is_file(self::DB_NAME)){
    $this->_db = new SQLite3(self::DB_NAME);
    }else{
        $this->_db = new SQLite3(self::DB_NAME);
        $sql = "CREATE TABLE msgs(
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                title TEXT,
                category INTEGER,
                description TEXT,
                source TEXT,
                datetime INTEGER)";
        $this->_db->exec($sql) or die($this->_db->lastErrorMsg());
        $sql = "CREATE TABLE category(
                id INTEGER,
                name TEXT)";
        $this->_db->exec($sql) or die($this->_db->lastErrorMsg());
        $sql = "INSERT INTO category(id, name)
                SELECT 1 as id, 'Политика' as name
                UNION SELECT 2 as id, 'Культура' as name
                UNION SELECT 3 as id, 'Спорт' as name";
        $this->_db->exec($sql) or die($this->_db->lastErrorMsg());
    }
}
function __destruct(){
    unset($this->_db);
}
function saveNews($title, $category, $description, $sourse){}
function getNews(){}
function deleteNews($id){}
}
$news = new NewsDB;
interface INewsDB{ // other file(implement)
function saveNews($title, $category, $description, $source);
function getNews();
function deleteNews($id);
</code>

我收到以下错误:

Error Failed to load resource: the server responded with a status of 500 (Internal Server Error)

folder path /var/www/mysite mysite - 755; user: Me ubuntu 14.10 desktop P.S 

这个问题也与MySQL有关。但我在SQLlite上再试一次,但我不能解决它。

3 个答案:

答案 0 :(得分:0)

这似乎是权限问题。

确保您的数据库文件设置了读/写权限,您的文件夹/mysite可能具有0x755权限,您的文件 >很可能只有0x644,这是Linux / Apache的默认配置。

答案 1 :(得分:0)

与您连接数据库的用户是否有权创建表?

答案 2 :(得分:0)

我找到了自己的解决方案

我再试一次 - https://help.ubuntu.com/community/ApacheMySQLPHP

有所帮助

sudo find /home/user/public_html/ -type f -exec chmod 644 {} \;
sudo find /home/user/public_html/ -type d -exec chmod 755 {} \;
sudo chown user:group -R /home/user/public_html/

INSERT INTO category(id, name)
                SELECT 1 as id, 'Политика' as name
                UNION SELECT 2 as id, 'Культура' as name

UNION SELECT 3作为id,'Спорт'作为名称**; **“; //在所有这些查询中,我的问题消失了