laravel mysql数据库迁移:安装错误

时间:2013-08-05 13:46:35

标签: laravel laravel-4

在完成一些基本的laravel代码之后,我尝试了迁移。以下是我的app \ config \ databast.php文件 -

 return array(

        'fetch' => PDO::FETCH_CLASS,

        'default' => 'mysql',

    'connections' => array(

            'sqlite' => array(
                'driver'   => 'sqlite',
                'database' => __DIR__.'/../database/production.sqlite',
                'prefix'   => '',
            ),

            'mysql' => array(
                'driver'    => 'mysql',
                'host'      => 'myproject',
                'database'  => 'myproj',
                'username'  => 'root',
                'password'  => '',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
            ),

            'pgsql' => array(
                'driver'   => 'pgsql',
                'host'     => 'myproject',
                'database' => 'myproj',
                'username' => 'root',
                'password' => '',
                'charset'  => 'utf8',
                'prefix'   => '',
                'schema'   => 'public',
            ),

            'sqlsrv' => array(
                'driver'   => 'sqlsrv',
                'host'     => 'myproject',
                'database' => 'database',
                'username' => 'root',
                'password' => '',
                'prefix'   => '',
            ),

        ),

        'migrations' => 'migrations',

        'redis' => array(

            'cluster' => true,

            'default' => array(
                'host'     => '127.0.0.2',
                'port'     => 6379,
                'database' => 0,
            ),

        ),

    );

如您所见,默认是mysql数据库。然后在命令提示符下我尝试了这个。

php artisan migrate:make users 

输出是 -

created migration: 2013_08_05_110148_users
Generating optimized class loader

然后我试了这个

php artisan migrate:install

但是我得到了这样的错误 enter image description here

你可以看到它的显示"主机medismoCRM不允许连接到这个服务器。" medismoCRM是我在mysql服务器上完成的另一个项目。所以我检查了主机文件。主机文件中的行是这样的 -

127.0.0.1       localhost
127.0.0.1       medismoCRM
127.0.0.2       myproject

所以medismoCRM和当前项目myproject都有不同的IP。然后我也检查了apache中的httpd-vhosts.conf文件。我还有2个不同的主机,比如这个 -

<VirtualHost *:80>
    DocumentRoot "C:/Program Files/Zend/Apache2/htdocs/laravel-master/public/"
    ServerName myproject
    <Directory "C:/Program Files/Zend/Apache2/htdocs/laravel-master/public/">
        Options Indexes FollowSymLinks
        AllowOverride all
        # onlineoffline tag - don't remove
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.2
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Program Files/Zend/Apache2/htdocs/medismoCRM/"
    ServerName medismoCRM
    <Directory "C:/Program Files/Zend/Apache2/htdocs/medismoCRM/">
        Options Indexes FollowSymLinks
        AllowOverride all
        # onlineoffline tag - don't remove
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

所以当我尝试php artisan migrate时,有人能说出为什么错误会出现在命令提示符中:install?

2 个答案:

答案 0 :(得分:0)

您是否仍在phpinfo()安装了PDO?

创建文件phpinfo.php并将其放入文件<?php phpinfo(); ?>

图片示例:http://www.trirand.net/documentation/php/images/pdo_mysql.PNG

确保php.ini已加载PDO驱动程序,检查PDO行extension=php_pdo_mysql_libmysql.dll如果没有关于PDO扩展名,则不会加载驱动程序PDO。

检查PDO连接:

<?php
try {
    $dbh = new PDO('mysql:host=localhost;dbname=myproj', 'root', '');
    foreach($dbh->query('SELECT * from users') as $row) {
        print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>

在新文件上创建并检查您的PDO数据库是否真的有效。

答案 1 :(得分:0)

app/config/app.php中,请务必设置'url' => 'http://myproject'