创建应连接到数据库的shell时发生致命错误

时间:2009-04-23 07:41:18

标签: php mysql database cakephp

Fatal error: Call to undefined function mysql_connect() in
/opt/lampp/htdocs/cake/cake/libs/model/datasources/dbo/dbo_mysql.php on line 370

//shell
<?php

class ReportShell extends Shell
{
    var $uses = array('Customer');
    function main()
    {
            $customers = $this->Customer->find('all');
            var_dump($customers);
            $this->out('lol my first CakePHP shell is baked');
    }
}

?>

//model
<?php

class Customer extends AppModel
{
    var $name = "Customer";
    var $useTable = "customer";
    var $hasMany = array
    ('CustomerPrice',
     'Order' => array('foreignKey' => 'customer_id'));

    // Validation settings
    var $validate = array(
            'customer_id' => array(
                    'rule' => 'numeric',
                    'message' => 'A customer ID should be numeric !'
            ),
            'customer_number' => array(
                    'rule' => 'numeric',
                    'message' => 'A customer number should be numeric !'
            ),
            'customer_name' => array(
                    'rule' => 'notEmpty',
                    'message' => 'A customer number should be numeric !'
            )
    );


    /**
     * Function to retrieve Customer data
     *
     * @param string $response_type - CakePHP find() type
     * @param array $response_setting - CakePHP find() parameter array (set$
     * @param int $customer_id - Find customer by customer ID
     * @param int $customer_number - Find customer by customer number
     * @param string $customer_name - Find customer by customer name
     * @param int $customer_billing_month - Find customer by customer billi$
     * @param int $customer_start_date - Find customer by start date
     * @param int $customer_end_date - Find customer by end date
     * @param string $customer_email - Find customer by customer e-mail
     */
    function FjmCustomerGetCustomer($response_type, $response_setting = arr$

            /* Conditions: Find Customer by customer data */
            if($customer_id)
            {       $response = $this->Customer->findByCustomerId($response$
            if($customer_number)
            {       $response = $this->Customer->findByCustomerNumber($resp$
            if($customer_name)
            {       $response = $this->Customer->findByCustomerName($respon$
            if($customer_billing_month)
            {       $response = $this->Customer->findByCustomerBillingMonth$
            if($customer_start_date)
            {       $response = $this->Customer->findByCustomerStartDate($r$
            if($customer_end_date)
            {       $response = $this->Customer->findByCustomerEndDate($res$
            if($customer_email)
            {       $response = $this->Customer->findByCustomerEmail($respo$

            if(!$customer_id || !$customer_number || !$customer_name || !$c$
            {       $response = $this->Customer->find('all', $response_sett$

            return $response;
    }

    /* FjmCustomerGetCustomerByProduct
     * FjmCustomerGetCustomerByOrder
     * FjmCustomerGetCustomerByBill
     * FjmCustomerGetCustomerByHandle
     */
}

?>

//database config php
    var $default = array(
            'driver' => 'mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'root',
            'password' => 'pwd',
            'database' => 'fjm_pps',
            'prefix' => 'fjm_',
    );

3 个答案:

答案 0 :(得分:5)

“致命错误:调用未定义的函数mysql_connect()”表示您的PHP安装中没有包含MySQL库。

检查你的php.ini并确保激活了mysql扩展。需要取消注释“extension = mysql.so”(或“extension = php_mysql.dll”)。

Google帮助您将PHP库包含在PHP安装中。

答案 1 :(得分:4)

另请注意,在某些安装上(debian会介意),如果不是全部,cli-php和apache-php都有分开 php.ini:s。因此,在一个中启用mysql并不一定对另一个有帮助。使用phpinfo()从。

中找出它在寻找php.ini的位置

答案 2 :(得分:1)

答案是php cli中的mysql扩展未激活或安装