小编Mil*_*dev的帖子

关于PHP 5实践中的一个例子的问题

嗨,我不明白为什么一本php书的作者在公共函数中使用$ disks = 1 __construct($ disks = 1)?

我试图用$ disks替换$ disks = 1,它也有效.作者为什么这样做?

<?php
// Define our class for Compact disks
class cd {
    // Declare variables (properties)
    public $artist;
    public $title;
    protected $tracks;
    private $disk_id;

    // Declare the constructor
    public function __construct() {
        // Generate a random disk_id
        $this->disk_id = sha1('cd' . time() . rand());
    }

    // Create a method to return the disk_id, it can't be accessed directly
    // since it is declared as private.
    public function get_disk_id() …
Run Code Online (Sandbox Code Playgroud)

php class object

1
推荐指数
1
解决办法
130
查看次数

通过PostgreSQL为数据库中的列设置默认值

我正在做我的第一个数据库项目.

我想知道如何false将以下SQL -query作为默认值

...
MODERATOR_REMOVAL boolean NOT NULL
...
Run Code Online (Sandbox Code Playgroud)

上下文

 CREATE TABLE Questions 
 (
     USER_ID integer FOREIGN KEY 
                     REFERENCES User_info(USER_ID) 
                     PRIMARY KEY 
                     CHECK (USER_ID>0), 
     QUESTION_ID integer FOREIGN KEY REFERENCES Tags(QUESTION_ID) 
                         NOT NULL 
                         CHECK (USER_ID>0), 
     QUESTION_BODY text NOT NULL,           -- question must have body 
     TITLE varchar(60) NOT NULL,            -- no empty title$                                
     MODERATOR_REMOVAL boolean NOT NULL,    -- by default false$     ///       Here
     SENT_TIME timestamp NOT NULL
 );
Run Code Online (Sandbox Code Playgroud)

你怎么能设置的默认值是false针对MODERATOR_REMOVAL在PostgreSQL?

sql database postgresql ddl

1
推荐指数
1
解决办法
9291
查看次数

循环语句的批处理文件

我把下面的批处理文件放在一起; 我对批处理文件没有多少经验,我无法弄清楚文件失败的原因,并显示错误消息:

DO命令是意外的.

看下面的代码,有谁知道我做错了什么?谢谢.

@ECHO OFF
REM Set arguments supplied by Subversion 
SET REPOS = %1
SET REV = %2

REM Set working directory path 
SET WORKSPACE = D:\apache\htdocs

REM Assign changes to variable 
SET CHANGES = svnlook changed %REPOS% -r %REV% 

REM Update only changed files  
FOR /f %%a IN %CHANGES% DO svn update %%a
Run Code Online (Sandbox Code Playgroud)

windows for-loop batch-file

1
推荐指数
1
解决办法
2400
查看次数

为什么Postgresql会像Geokit这样失败?

我刚刚开始使用Rails为我正在构建的应用程序玩geokit.我的记录得到了地理编码,但是当我进入控制台看看我能用它做什么时它会爆炸以下内容:用户是我的数据库中带有lat和lng的用户对象

>> Restaurant.find(:all, :origin => user) 

  Restaurant Load (0.0ms)   PGError: ERROR: operator does not exist: 
numeric - character varying 
LINE 1: ...*, SQRT(POW(111.1819*(-33.872517-restauran... 
 ^ 
HINT: No operator matches the given name and argument type(s). You 
might need to add explicit type casts. 
: SELECT *, SQRT(POW(111.1819*(-33.872517-restaurants.lat),2)+ 
 POW(76.7136337302943*(151.205536-restaurants.lng),2)) 
 AS distance FROM "restaurants" 
ActiveRecord::StatementInvalid: PGError: ERROR:  operator does not 
exist: numeric - character varying 
LINE 1: ...*,                   SQRT(POW(111.1819*(-33.872517- 
restauran... 
                                                             ^ 
HINT:  No operator matches the given name and argument type(s). You 
might …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails geokit

1
推荐指数
1
解决办法
939
查看次数

PostgreSQL表设计 - 如何避免重用ID

我正在使用Postgres数据库设计一个具有相当复杂的桌面设计的应用程序,并且我坚持一点,我希望有人可以提供建议.

我有几个表,每个表都有一个功能ID(或fid).不同类型的实体具有不同的属性模式,因此我必须为每种类型创建不同的表.但是,我想确保fids在所有实体类型中都是唯一的.

如果我有三个实体类型,Entity1/2/3,由以下3个表表示:

Entity1             Entity2             Entity3
    fid                 fid                 fid
    attribute1          attribute2          attribute3
Run Code Online (Sandbox Code Playgroud)

如何确保系统中的任何位置都没有重复的fid?

谢谢!

sql postgresql

1
推荐指数
1
解决办法
905
查看次数

使用java代码列出特定PostgreSQL数据库中的所有表

实际上我已经google了一点,我需要相应的SELECT命令来跟随PostgreSQL shell命令:

\dt schemaname.*
Run Code Online (Sandbox Code Playgroud)

我设法使用以下代码获取所有数据库:

            Statement statement = (Statement) connection.createStatement();
            ResultSet rs = statement
                    .executeQuery("SELECT datname FROM pg_database");
            while (rs.next()) {
                System.out.println("DB Name : " + rs.getString(1));
           //i need another while here to list tables 
           //inside the selected database
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下声明,但没有运气:

statement.executeQuery("SELECT table_schema,table_name FROM "
                                + rs.getString(1)
                                + " ORDER BY table_schema,table_name");
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

org.postgresql.util.PSQLException: ERROR: relation "template1" does not exist
  Position: 37
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
    at com.isiran.rayten.rg.db.bare.wrapper.PGWrap.main(PGWrap.java:64)
Run Code Online (Sandbox Code Playgroud)

java sql postgresql

1
推荐指数
2
解决办法
5972
查看次数

PostgreSQL中的跨数据库查询

我正在尝试在Postgres中构建一个查询.我的背景是在SQL Server中,所以我有一些语法上的挑战.我的查询需要在两个单独的服务器上打两个单独的数据库.我需要在数据集之间进行连接.基本上,我在db1中有一个用户登录活动的表.每次用户登录网站时都会添加一个条目.在db2上,我有一个购买表.对于每一天,我需要看到:登录了多少人以及登录的用户中有多少人进行了购买.

我的表看起来像这样:

Logins                Purchases
---------             ---------
ID                    User_ID
User_ID               Amount
LoginDate 
Run Code Online (Sandbox Code Playgroud)

如果我的Purchases表上有日期字段,这将很容易.但事实并非如此.所以,目前,我正在尝试以下方面:

SELECT 
  // Somehow get the number of logins for the given day here
  // Somehow I need to get the number of purchases for the given day here      
  TO_CHAR(TO_TIMESTAMP((LoginDate/1000) - 14400), 'MM/DD/YYYY') AS the_day
FROM 
  db1.Logins AS t1,
  db2.Purchases as t2
GROUP BY the_day
ORDER BY the_day;
Run Code Online (Sandbox Code Playgroud)

如何在Postgres中获取每天的登录和购买次数?谢谢!

sql postgresql cross-database

1
推荐指数
1
解决办法
1万
查看次数

MYSQL错误

忍受我,我对这一切都有点新鲜,

我在我的PHP脚本中运行此查询:

$insertQuery = "INSERT INTO blog_articles 
     VALUES '$title', $tags', '$category', '$blog', '$author', '$date'";
Run Code Online (Sandbox Code Playgroud)

然后我运行这个脚本:

    if ($result = $connector->query($insertQuery)){
    // It worked, give confirmation
    echo '<center><b>Article added to the database</b></center><br>';
}else{
    // It hasn't worked so stop. Better error handling code would be good here!
    die (mysql_error());
}
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在第2行附近使用"Title Number 1,General,Blogging,Kayaking,General,Tgis是博客编号spelli"时使用正确的语法

但我不知道错误是什么,它看起来很好,所以如果有人可以帮助我,那将是非常感谢

php mysql

0
推荐指数
1
解决办法
151
查看次数

SQL Server

大家好我拍了数据库快照.然后,如果我做了更改,那么这些更改将反映基础数据库或快照数据库?

当我拍摄数据库快照时,它会创建另一个数据库吗?

sql-server

0
推荐指数
1
解决办法
85
查看次数

是否可以轻松检测或预测SQL中的主键冲突?

我的问题是我想运行一个查询来检查我使用的数据是否与数据库中已有的数据重复,例如我有一个产品代码,并希望停止多次列出相同的项目,这产品代码是主键.
我可以避免这样做:

SELECT ProductCode FROM tblProducts WHERE ProductCode = '12345'
Run Code Online (Sandbox Code Playgroud)

然后检查任何返回的记录,或者是否有更优雅的解决方案,我不介意使用这种方法,但它看起来很笨拙.这只是对我的代码的一些额外验证,因为产品的插入应该只发生一次 - 但我想要对此进行错误检查,因为由于刷新或使用后退按钮(基于Web的系统)而输入了重复项.

不知道这是P = NP型问题还是我在思考这个问题?
我的数据库是MS SQL Server 2000,如果这有帮助.

sql database sql-server primary-key

0
推荐指数
1
解决办法
597
查看次数