connect to mySQL using xampp - php

Im using xampp control on macbook and trying to connect to 'localhost/phpmyadmin'. I have apache and mySQL both running but im getting an error
#1 - Can't create/write to file '/var/folders/kb/6g_npz7s1511w39k7v224gq80000gn/T/#sql4e6_1_2.MYI' (Errcode: 13)
Any ideas about what this might be or how i could connect?

Usually you'd get that error because the directory that MySQL is using to write temp files to isn't writeable by the mysql user; usually that directory would be /var/tmp or something similar. Try starting mysql with the --tmp-dir=/var/tmp and see if it still complains. See http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_tmpdir

check the port of the apache .... by selecting checkport ... and in the browser set the url as: localhost:(port number)/phpmyadmin

Related

ISAM Table Not Found, SQL state S0000 in SQLExecDirect

PHP Version: 7.0.14
Working on Windows Server 2012
Database files are in D: drive
Website/Application is assigned to the Application pool correctly
Assigned Application pool has the permissions to D: drive
Trying to connect and fetch information from ToppSpeed Database.
Created DSN correctly using Topspeed ODBC Driver.
I have created a sample script to verify if it is working or not.
odbctest.php
$conn=odbc_connect("DSN_NAME",'',''); //Make a coonection to DSN
if (!$conn){
exit("Connection Failed: " . $conn);
}
$sql="SELECT * FROM ExampleTableName"; // Query String
$rs=odbc_exec($conn,$sql); //Execute Query <--- Error Line
if (!$rs) {
exit("Error in SQL");
}
while (odbc_fetch_row($rs)){
var_dump(odbc_result($rs,1));
}
odbc_close($conn);
Error:
PHP Warning: odbc_exec(): SQL error: [SoftVelocity Inc.][TopSpeed ODBC Driver][ISAM]ISAM Table Not Found, SQL state S0000 in SQLExecDirect in C:\inetpub\wwwroot\projectFolder\odbctest.php on line 9
Working: When I run same file on PHP inbuilt server using command > php -S localhost:8002
and run file in a browser at http://localhost:8002/odbctest.php Everything works fine.
Working: When I run file in command line > php odbctest.php It works fine I got data from the table.
Not Working: I have added the website in IIS Manager, bind the website(physical path is C:\inetpub\wwwroot\projectFolder ) with the local IP
When I open that odbctest.php in a browser with local IP I am getting Table NOT Found error.
Same Script, Only difference is it is running on Command Line and not on IIS server, It is running on PHP inbuilt server and not working on IIS.
other Technical Difference is
I have put one PHP file to see PHP information on both servers.
Here is the only difference I found in that.
Working On PHP inbuilt server: In PHP info Server API is: Built-in HTTP server
Not working on IIS Server: in PHP info Server API is: CGI/FastCGI
there is not issue in DSN string because when I change the DSN string with unknown it identifies that there is something wrong in DSN string.
I think there might be some permission issue when trying to access data from IIS server (PHP runs on CGI/FastCGI).
I am wondering if there is permission issue why the error says table not found!!
I don't find any good documentation for TopSpeed Database connection error as this database is not widely used.
Any suggestion or idea? Please advise. Thank you in advance.
The database SQL error was not stating anything about permission,
so I created a simple another PHP script to append data to TEXT file.
I ran that PHP script with two test cases on the IIS server
Test Case 1: Write in a text file which resides in the project directory(same server)
And PHP script executes correctly and it wrote data to text file.
Test Case 2: I change the text file path with the file D:\some_directory\logfile.txt (Resides on D drive)
And when I ran it again script again I got the following error:
Warning: file_put_contents(D:\some_directory\logfile.txt):
failed to open stream: Permission denied in
C:\inetpub\wwwroot\project-directory\write.php on line 12
It confirms there is some problem with the Permissions
App pool assigned to the Website in IIS manager already had the permission to D: Driver. So it was not the problem.
In more research, I found that
we need to identify the USER first that we need to provide the permissions and the user is the value of "Anonymous user identity"
https://stackoverflow.com/a/32033941/5236174
https://www.iis.net/configreference/system.webserver/security/authentication/anonymousauthentication?showTreeNavigation=true
I saw that the value of Anonymous user identity was not the Application Pool!!
I changed that to the Application pool identity.
So now the website/application's anonymous user identity become the App pool and that has correct permissions.
Afthesethis changes, everything works perfectly fine as there is no permission issue.

Connecting to MYSQLi through Terminal in Mac OS using MAMP

I am trying to run my PHP script via Terminal in Mac. When I try to run the script, I am getting this error:
Warning: mysqli_connect(): (HY000/2002): No such file or directory
This is how I am trying to connect:
mysqli_connect('localhost','root','root','my_db');
I also tried to connect using the host: 127.0.0.1 instead of localhost and I then got this error:
Warning: mysqli_connect(): (HY000/2002): Connection refused
From what I've read online it might have something to do with mysql socket, but whatever I try to do to get this to work doesn't help.
I even tried to connect using the following as my host:
:/Applications/MAMP/tmp/mysql/mysql.sock
:/var/mysql/mysql.sock
Any idea what can be the problem/solution?
Had the same issue. Here's what I did.
Open Terminal (/Applications/Utilities/terminal.app)
Use your favorite text editor to create/edit ~/.bash_profile. For instance, if you're using vim, type vim ~/.bash_profile. I use TextMate, so I typed mate ~/.bash_profile.
Add these lines:
export MAMP_SQL=/Applications/MAMP/Library/bin
export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.10/bin
export PATH="$MAMP_SQL:$MAMP_PHP:$PATH"
These lines ensure that the first versions of MySQL and PHP that are found (and therefore used) are the versions used by MAMP. NB: Make sure that php5.5.10 matches the version MAMP is using. You can check this against http://localhost:8888/MAMP/index.php?page=phpinfo&language=English by default. SAVE THE FILE (I shouldn't have to save this, but invariably someone complains that it doesn't work).
Close your terminal window and reopen. This restarts the shell, which will load your .bash_profile script.
Type which php. You should get something akin to /Applications/MAMP/bin/php/php5.5.10/bin/php
Type which mysql. You should get something akin to /Applications/MAMP/Library/bin/mysql
If for any reason you get something different than the responses from 5 and 6, go back and check your .bash_profile; chances are you just neglected to save it properly.
If you have MySQL installed on your computer, you can do the following command:
mysql -u "username"
replacing "username" with the username of your computer
NOTE: often times root does not work, try the username of your computer

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

everyone. I'm a student and very inexperience newbie with PHP . Before you mark this as irrelevant or duplicate or anything. Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla
uploaded all the files to the server side public html and tried to run the file in browser
by using: my_school_link/my_username/
and I have this error
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
<?php
mysql_connect('host_name', 'user_name', 'password');
mysql_select_db('my_database_name');
?>
I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock*
and I have tried the following
view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers)
have entered the correct hostname, username and password
run as admin
checked if mysql is running ( it is so is Apache)
MySQL socket specified in php.ini was never edited so it is in default mode
cant locate mysql config file, or my.cnf, or etc folder
What could the problem be? Please if anyone could help me, please tell me what's wrong.
Please provide a step-by-step guide. and file extensions if need to save files....
Is there any additional things i can add to help anyone understand my problem better?
if yes, please let me know...this is my last resort so Thank you so very much in advance for any help.
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
This error appear when your mysql server is not running. If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.)
If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
Another reason may be that you are using the wrong host name while connect.
Don't use mysql_connect it is deprecated and instead you should use MySqli

Wordpress installation - php and mysql are not talking to each other to access database?

I'm trying to get a wordpress local install working on my Mac.
I've recently set up a database, username and password using the MySQL client as per the instructions in the wordpress codex. That part is ok.
When I go to the local site on my computer I'm prompted by wordpress to set up the wp-config.php file. Putting in the same details that definitely work with the MySQL client returns an error.
Manually updating these details in the 'wp-config-sample.php' file and renaming it as 'wp-config.php' also doesn't work - I'm now greeted with a big bold message: "Error establishing a database connection".
From what I can gather, php and mysql are not communicating with each other properly.
I've changed the apache 2 configuration file found in 'etc/apache2/httpd.conf' and uncommented the line which loads the php5 module: LoadModule php5_module libexec/apache2/libphp5.so
and restarted the apache server. This has still not fixed my problem. I'm stuck on what to do next... help appreciated please!
It's been fixed now.
php was looking in the wrong place for the mysql.sock file, and couldn't communicate with the mysql database, meaning wordpress couldn't be set up.
On the command line I typed
ps aux | grep mysql
to bring up as much info about mysql that I could. From this I saw that the mysql socket on my computer is being used at /tmp/mysql.sock
Meanwhile, in the "wp-config.php" file, I changed the line define('WP_DEBUG', false); to define('WP_DEBUG', true); and refreshed my web browser that was showing my localhost setup. This now said a lot more info than "Error establishing a database connection" - infact I could see that the mysql.sock was not configured correctly at all.
Creating a 'phpinfo.php' file with just the single line of code <?php phpinfo(); ?> was the pivotal turning point for me.
Putting that 'phpinfo.php' file in my localhost directory and then viewing it from my web browser not only definitely confirmed that the mysql.sock file was not configured properly, but it also showed where the configurations were being loaded from on my machine: '/private/etc/php.ini'
The next thing I did was open up the 'php.ini' file in a text editor and doing a quick find and replace to update the correct location of mysql.sock.
Finally, a restart of the local apache server needed to be done to fully update all the new settings that I'd been fiddling about with.
sudo apachectl restart
Now everything works fine!
The Error-Message "Error establishing a database connection" indicates clearly, that the php-script can not establish the connection. This can have one of the following reasons:
Your host in the wp-config.php is not correct.
The mysql-server does not listen on that host
The user you set up in the mysql has no privileges to connect the way you are trying
The firewall blocks the access of the php-script to your mysql-host
Try to connect the database with the same settings of your wordpress using Sequel Pro (or any other GUI to connect a mysql database). If the connection works, the problem 2. and 3. isn't your problem.
Look in your firewall-log to make sure 4. is also not your problem.
If all problems are excluded (even 1. after a final check), try to run something like phpMyAdmin to connect your database, to make sure your php-installation has the needed drivers.

create mysql database on mac os x

I know this sounds a little ridiculous, but I'm just honestly wondering how I can create a MySQL database on my Mac OS X machine. I have MySQL installed (as far as I know) as well as PHP, and I'm wondering how I can create one.
I have downloaded a sample PHP ecommerce site to kind of delve into what I'm trying to familiarze myself with, and the PHP files are attempting to connect to a nonexistant database, which I'm hoping to create right now.
Do they have an extension of .sock? Because, here is the "error" code when I try to test a PHP page referencing the nonexistant database:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in< /Library/WebServer/Documents/plaincart/library/database.php on line 4 Warning: mysql_connect(): No such file or directory in
/Library/WebServer/Documents/plaincart/library/database.php on line 4 MySQL connect failed. No such file or directory
My guess is you are specifying the database server as localhost somewhere. Try 127.0.0.1 instead.
I had this problem once with WordPres on Mac OS X. The answer was to name the local machine in the db connection configuration 'Localhost' with capital 'L', because on OS X localhost != Localhost.
I had the same problem with MySQL on the OSX. It turned out that the MySQL server was actually set up to use a different socket than the default setting in PHP.
PHP was looking in /var/mysql/mysql.sock, while mysql was creating the socket in /tmp/mysql.sock.
I fixed it by editing the php.ini and set mysql.default_socket = /tmp/mysql.sock

Categories