I am nearing the collapse. I am very grateful for your answers to several questions about connecting to the database and system settings in the mamp environment!

Source: Internet
Author: User
I am nearing the collapse. I am very grateful for your answers to several questions about connecting to the database and system settings in the mamp environment! Overview: I recently learned PHP programming. The system is mac OS X 10.11 and the mamp PRO (3.1) integrated environment is used.

Problem: put a simple echo php code in the htdocs folder under mamp to display the code, but cannot connect to the database, as shown below,
For example, enter the database connection test code as prompted on the mamp homepage:

$user = 'root';$password = 'root';$db = 'inventory';$host = 'localhost';$port = 8889;$link = mysqli_init();$success = mysqli_real_connect(   $link,    $host,    $user,    $password,    $db,   $port);

Http: // localhost: 8888/The webpage is blank with no prompt.

Test the following code:
    $host='localhost';    $user='root';    $password=‘root’;     $database=‘mysql’;    $port=8889;    $socket=':/Applications/MAMP/tmp/mysql/mysql.sock';    $dbc = mysqli_connect($host, $user, $password, $database,$port,$socket) or die(mysqli_connect_error());

Webpage: No such file or directory


Test the following code:
 

Zend displays Warning: mysql_connect (): No such file or directory in/Applications/MAMP/htdocs/tags. php on line 2
OK
But the localhost is false. What is this?

I have been confused about this problem for two days, and the root user who switched the system has also tried it.

For the first time, I tried to run mysql-uroot-p on the terminal.
Show-bash: mysql: command not found
The same is true for mysql that comes with the mamp startup system.-bash
According to the online query http://zhidao.baidu.com/link? The url = login attempt to change the password is successful, but no matter how many times it is changed, the password is displayed incorrectly.

Will mysql of MAC conflict with mysql of mamp?

I have tried to solve the problem as much as possible, but I can only ask you about my limited capabilities. I really want to use PHP to do something. but I can't help but leave it here. I would like to offer it at 100 points, thank you!


Reply to discussion (solution)

Open the error log and view the error
Check whether mysql extension is installed in php.
Check whether mysql is started and the listening port number.

MAC has never been used. we recommend that you install a virtual machine, a windows system, and download and use the wamp environment ,.

Your two pieces of code, one is mysqli_connect, and the other is mysql_connect.
Which one are you using? You need to install the php-mysql php-mysqli extension for both of them.

 


Check whether mysql and mysqli extensions are available in the output. if not, the installation is unsuccessful. You need to reinstall the two extensions.

I tried a lot of methods to sum up the problem that "No such file or directory" is reported when I connect to MySQL in PHP.
Baidu: http://www.linuxidc.com/Linux/2012-12/76150.htm this should be the most possible solution
However, you can find mysql. default_socket, mysqli. default_socket, and pdo_mysql.default_socket on the phpinfo page that comes with mamp.
However, no file is visible in the finder, so no matter what it is...
Article 3: Start mysql (see Note 2), execute the command STATUS, and write down the UNIX socket value
How to run this STATUS command? Do not understand solution!

The http://ju.outofmemory.cn/entry/144933 says.
"The solution is invincible and simple. it is to make a soft chain for the PHP binary in the sandbox and put it under/usr/local/bin. for example, name it php55, when you execute the script to connect to the database later, remember to use php55 as the interpreter to run it smoothly."

How can we solve this problem!

I tried the soft link method. it seems useless and I have to crash again.
Terminal input In-s/Applications/MAMP/tmp/mysql/usr/local/bin
Display:-bash: In: command not found
I'm going ....

I don't know about mac, but the command not found is a bit familiar. it seems to be a problem with system environment variables.

It is estimated that there are two php versions for the mac of the landlord, namely php56 and php55.
Look
Php-v
/Usr/local/bin/php-v

Check whether it is the same. if it is not the same, it is the problem.

You only need to connect/usr/local/bin/php to the installed php path.

Enable the error message first:

ini_set('display_errors','on');error_reporting(E_ALL);

Check for any error messages.

Finally, I found that the port number of the database in PHP is wrong. it will be done after modification. thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.