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

Jan*_*man 1 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_',
    );
Run Code Online (Sandbox Code Playgroud)

zom*_*bat 5

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

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

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