Timestretch Logo Atom Visuals
 Home  Site News  Articles  Desktop Pictures  Erik's Artwork  Music  Software 

Site News
+ Articles
12 inch PowerBook G4 Review + Airport Extreme
Apple Vrs Dell Notebooks
Apple, Please Open up the iPod API!
Asm Programming Using Jmp/Call
Assembler Programming for Intel and PPC on OSX
Canon ZR10 Quick Review
iPod Review... (2)
OS X & Linux Features Compared
PHP, MySQL, and Smarty Programming Intro
Spam Graph
- Web Development with MySQL and PHP4 and MacOS X
Writing Secure PHP Applications
Desktop Pictures... (4)
Erik's Artwork
Music
Software... (3)

Search:
Site News:
· I'm a mac.
09/22/2008
· Asm Programming Using Jmp/Call
05/04/2008
· Assembler Programming for Intel and PPC
05/14/2007
· Url2thumb - Generate Thumbnails from URLs
09/22/2006
· Ruby, Io, Python, Java, C Benchmark
09/22/2005
· Linux on iPod review from xlr8yourmac
12/27/2004
· Writing Secure PHP Applications
03/29/2004
· RealNetworks CEO: Apple needs to open iPod
03/23/2004
 

Site News | RSS


Home > Articles >

Web Development with MySQL and PHP4 and MacOS X

By Erik Wrenholt (erik@timestretch.com)

Learn how to install PHP4 and MySQL on MacOS X, and build a simple web based application that runs on MacOS X. This article assumes you have some experience with the Terminal, PHP, MySQL, and Apache already, and are ready to try MacOS X as your web serving platform. I recommend using OmniWeb 4.0 for this tutorial, but any web browser should work.

If you already have MySQL and PHP set up, you can go straight to the code. This PHP example takes care of creating a database and table the first time it is run, and initializes the database with some data.

Install PHP4 and MySQL

Install PHP4 and MySQL from Marc Liyanage's MacOS X Packages.

Follow the instructions found on Marc's web site to install PHP4 and MySQL. It went smoothly for me on both a HFS+ and UFS installation of MacOS X.

The PHP4 instructions are very easy to follow. You just need to type a few lines into the Terminal application. Easy!

The MySQL install is very simple also. Download mysql-3.23.xx.pkg.tar.gz and mysql-startupitem.pkg.tar.gz from Marc's site. Make sure you get the startup items download so that MySQL automatically starts up when you restart your server.

OK, now you should have PHP4 and MySQL installed. Read on and learn how to use this software to make web based applications.

Create a MySQL Database and Table

SQL is a complicated subject, but fortunately you don't need to know that much to begin using it in web based applications.

Each DATABASE you create can have any number of individual TABLES that belong to it. All data stored into the database has to be put into columns in a table. We can create a table by pasting a schema describing the table's columns into the MySQL shell.

MySQL allows you to run several different databases and control access to each database, and control access to each table in the database. The mechanism is provided by a special MySQL table called the Grant table. DevShed has some excellent articles on Grant tables.

There are countless books on the subject of database design, but one important thing you want to remember is to include a PRIMARY KEY for each table. I use unique_id for my PRIMARY KEY. Here is the schema used to create the table.

create table CONTACT_INFO (
    unique_id int(4) PRIMARY KEY 
    	AUTO_INCREMENT,
    first_name char(30),
    last_name char(30),
    phone char(20)
);

I learned to use MySQL on a Linux machine, so I'm used to managing my databases from a command line. There are graphical MySQL browsers available for MacOS X such as MacSQL, if you are uncomfortable with the command line.

Type "sudo mysql" to open the MySQL shell. 

this should print out:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6 to server version: 3.23.36

Type 'help;' or '\h' for help. Type '\c' to clear the buffer
mysql> 

Create the database then select it by typing the following commands to the MySQL shell.

mysql> create database CONTACT;
Query OK, 1 row affected (0.00 sec)

mysql> use CONTACT;
Database changed

Now you have created and selected a database. Simply paste in the schema above to create the table in the database. Don't forget the semicolon (;) at the end of your query. It in neccesssary to let MySQL know that your query is complete. Check to make sure that MySQL actually created the database by typing "show tables;".

Once you have verified that this has worked, go ahead and drop the CONTACT database. This permanently deletes the database. This is OK because the php code below automatically creates the database and table the first time it is run. Although you could do almost all of your database management from within php, the shell is more productive for certain tasks.

mysql> create table CONTACT_INFO (
    ->     unique_id int(4) PRIMARY KEY 
    ->     AUTO_INCREMENT,
    ->     first_name char(30),
    ->     last_name char(30),
    ->     phone char(20)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+-------------------+
| Tables_in_CONTACT |
+-------------------+
| CONTACT_INFO      |
+-------------------+
1 row in set (0.00 sec)

mysql> drop database CONTACT;
Query OK, 3 rows affected (0.01 sec)


Accessing the MySQL database from PHP

We are now ready to start coding in PHP. Create a file named "index.php" in the Sites folder of your home directory. You can do this from the command line by typing:

touch ~/Sites/index.php

Use your favorite text editor (bbedit, vi, TextEdit) to paste the following into the index.php file your created.

<?
	$database_name = "CONTACT";
	$table_name = "CONTACT_INFO";


//This is the information we initialize the database with.

	$first_name = "Erik";
	$last_name = "Wrenholt";
	$phone = "555-555-1234";

//Here is the schema for our database:
	
	$database_schema =  "CREATE table $table_name (
		unique_id int(4) PRIMARY KEY AUTO_INCREMENT,
		first_name char(30),
		last_name char(30),
		phone char(20)
	);";

	$dbh = mysql_connect("localhost","root","");

//Try to select CONTACT database. If we can't, try to create database.

	if (!mysql_select_db($database_name)) {
		
		//We don't have a database so make one
		
		if (mysql_create_db($database_name)) {
			echo "Database Created.<BR>";
		} else {
			echo mysql_errno().": ". mysql_error ()."";
		}
		
		//OK, database should be created now, so select it..

		if (!mysql_select_db($database_name)) {
			echo "Can't Select $database_name";
		}
		
		//Tell MySQL to create our schema..
		
		$res = mysql_query($database_schema,$dbh);

		if (!$res) {
				echo mysql_errno().": ". mysql_error ()."";
				return 0;
		}
		
		//This is how to add stuff to the database
		
		$query = "INSERT into $table_name
				( first_name,
				last_name,
				phone)
		values (
				'$first_name',
				'$last_name',
				'$phone');";
				
		$res = mysql_query ($query,$dbh);
		
		if (!$res) {
			echo mysql_errno().": ". mysql_error ()."";
			return 0;
		} else {
			//we added our first info to the database..
			echo "$first_name $last_name $phone added.<BR>";
		}

	}
	
	//"SELECT * FROM MYTABLE" is how you get EVERYTHING from one table
	
	$query = sprintf ("SELECT * FROM %s",$table_name);
	
	$res = mysql_query($query, $dbh);
	
	if (!$res) {
		echo mysql_errno().": ". mysql_error ()."";
		return 0;
	}
	//print out everything in our database.
	while ($thearray = mysql_fetch_array($res)) {
		extract ($thearray);
		printf ("%s %s %s retrieved from database.<BR>",
			$first_name, $last_name, $phone);
	 }


?>

Now you can access the php script in a web browser by typing this URL with your own username.

 http://127.0.0.1/~username/index.php

If all went well, you should have the following print out in your web browser.

Database Created.
Erik Wrenholt 555-555-1234 added.
Erik Wrenholt 555-555-1234 retrieved from database.

Comments

Good example for a bad technology 07/17/01

I'm just wondering if ther's anyone out there using this kind of *technology* ! So happy to see that I can use more ellegant way of coding.

WO is Me!!!


PHP4 & MySQL = Good Technology 07/17/01
Erik Wrenholt

Web Objects do have some advantages, but you certainly don't have as many OSs to choose from to deploy your web application. I easily moved my web site from Linux to MacOS X in a couple hours. Not only that, PHP4, MySQL, and Apache runs on a number of other server OSs such as Windows, Solaris, and BSD OSs.


The hostname should match the DNS 07/18/01
Erik Wrenholt
erik -at- timestretch.com

I had a reader report trouble installing MySQL when their hostname did not match the name you get with an nslookup. Open a terminal and do a "nslookup your.ip.here" with your IP address. The server will reply with your domain name. Type "sudo hostname newhostname". Enter your root password and see if that fixes errors you were getting during installation.

This same procedure was neccessary for me to run the WebObjects examples Apple included with MacOS X CDs.


Having a bit of trouble with MySQL 07/21/01
tippedcow -at- jeffreyweb.com

I've attempted to install MySQL but I can't seem to connect to the server. It is running per the processes viewer however when attempting t connect I recieve: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"

The MacOS X machine is a LAN client and does not have it's own domain other than localhost.

Any thoughts?

Thanks a lot for proving that OS X rocks for web dev!


Good Stuff Indeed 07/23/01

Thanks Eric! I'm a app developer and I've been lagging on getting this going on my home g3. You just made the process nice and painless. Next I can convince work to move to X/php/mySQL - We're cf and SQLserver right now. Wait, actually next is a beowulf configuration of g4's on X. Yeeaah.


X Serving 07/31/01
geraldartman -at- mediaone.net

Lets replace LAMP with XAMP

Linux/Apache/MySQL/PHP

OSX/Apache/MySQL/PHP

with phakt you can use UltraDev4 to do most all development using PHP or JSP.


Great Site, but I'm stuck... 08/31/01
mac -at- chinatron.com

Thanks to both this site, and the marc's page listed above, I was able to get PHP and MySQL setup perfectly, and got my first Database created, but I also took mark's advice and created a 'secure the open master account in the default installation:' I don't think you covered this on this page, a needed to use ' sudo mysql -p ' and now I am getting 'Access denied' errors on my page.

Also, I tried copy / paste into 'TextEdit'
but I had problems due to the RTF format, so I used bbedit instead which worked fine.

Any idea's how I can fix your index.php to work with the password I have added?

Thanks again for this site, it has helped me loads!


Great Site, AND I'm NOT stuck anymore... 09/03/01
mac -at- chinatron.com

WoooHooo! - I started again, this time with root access, and it all works fine...

Thanks!


Finally, a tutorial that makes sense 09/04/01
djwig -at- earthlink.net

I just had to thank you for your well written, informative, lucid explanation of getting started with MySQL/PHP. I've been pulling my hair out for weeks just trying to find an explanation of this stuff that actually makes sense. Thanks.


problem 09/06/01
ssample -at- massconfusion.com

I am getting an error saying that the database cannot be created, permission denied. Also getting login error saying that permission deied from root@localhost - when logged in as root...what's going on, and how do I fix it?


hope this helps 09/19/01
whilden -at- mac.com

The permission denied can be be resolved by hard coding the root password in $dbh = mysql_connect("localhost","root","(password)"). I dont think is it so secure but good for learning.


security 10/21/01
roscoespinoza -at- yahoo.com

Yeah, that doesn't seem so secure to me either. How would this be gotten around? Anyone?


access denied?? 10/29/01
clappstar -at- home.com

I have mysql and php successfully installed. But as I am starting your tutorial I get the following error after the command
sudo mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

could you let me know haw to fix this?
I am quite anxious to learn and your tutorial is most helpful.


nothing displayed 11/07/01
lovnish -at- mac.com

Installed everything and tried this tutorial. The browser does not show me anything when i type http://127.0.0.1/~username/index.php

just a black file...no errors, nothing. What could be the problem?

HELP


nothing displayed 11/07/01

that's blank file not black...oops


Re: nothing displayed () 11/18/01

the blank file: did you forget to drop the database you created in the command line?
mysql> drop database CONTACT;


thanks, 11/21/01

finally mastered the triumvirate (in apx. 3 h, departing from a clean sytem install) I hope the next update will not break all down.
marc liyange advised to set the mysql password. as complete php/mysql beginner i had first to find out that in the line '$dbh = mysql_connect("localhost","root","****"); the db- password had to been set. now all works as it should

lubowsky


Thank you 11/26/01
sumitrai -at- mac.com

Finally someone has made a good tutorial to get something up and running!!!!!

I wish everyone started like this!

Cheers :-)


  12/04/01

Yep, it really really works! Well, it does once you figure out the root password issue, like lubowsky commented. This has been a long time coming, I've been waiting for a stable mysql release that fixed the shutdown bug. But now I'm concerned about mysql auto-shutdown, we have a gadget to do a startup on boot, but does it safely shut down when the CPU is shut down?


password, user and such kidding things.. 12/12/01
az -at- az.org

Well then, first of all : THANKS it works :-)
Then a little problem, Mysql works well in the terminal, I add, drop and play with it quite fine, Php also is really funny to use but but but...
I can't connect this damned mysql from a web browser : the user (root) and the password I give (which is the same that I give in the terminal) doesn't works :-(
I tried to use the PhpMyAdmin also and I have the same problem of authentification.
Does anybody have any idea to help me? Yu're welcome.
--
az


phpMyAdmin 12/12/01
az -at- az.org

Well..it works fine...download put it in yur local website set the config.inc.php to "root" as user and nothing more in this file and...it runs fine :-)
so no password is needed when you log as root.
I think that I will put a .htaccess right now...
Bye
--
az


Wow 12/16/01

that was quick and easy.


Help plz 12/24/01
skumancer -at- mac.com

Warning: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 19

Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 19

Warning: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 22

Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 22

Warning: MySQL: A link to the server could not be established in /Users/sku/Sites/index.php on line 22

Warning: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 26

Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 26

Warning: MySQL: A link to the server could not be established in /Users/sku/Sites/index.php on line 26
1045: Access denied for user: 'root@localhost' (Using password: NO)
Warning: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 34

Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in /Users/sku/Sites/index.php on line 34

Warning: MySQL: A link to the server could not be established in /Users/sku/Sites/index.php on line 34
Can't Select CONTACT
Warning: Supplied argument is not a valid MySQL-Link resource in /Users/sku/Sites/index.php on line 40
1045: Access denied for user: 'root@localhost' (Using password: NO)


This is what I get from the index.php...what can I do? I am new to PHP, terminal.app and MySQL.


Missing Password 12/27/01
Erik Wrenholt
erik -at- timestretch.com

If you have set a password for your mysql server, you will need to modify this line:

$dbh = mysql_connect("localhost","root","your_password");


thanx 01/07/02
superfunkomatic -at- mac.com

well, after all i've heard about mysql, and databases i thought i'd be in for a rough ride. config was easy, now i'm off to learn more PHP to build and create stuff in web apps. thanx, great to see this work for the Mac community


Nothing happens 01/08/02
nick -at- hotmail.com

when i open the php page thru my browser, i only see the php file and nothing else. It's just like viewing a static page.


is using root good? 01/19/02
sgarci -at- mac.com

Is is really a good idea to log in as "root" to query the DB?


Can't access sql admin 01/21/02
hoffj -at- hoff.org

I followed the steps, but I get the following error:

[localhost:~] hoffj% sudo mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
[localhost:~] hoffj%


Sweet :-) 01/25/02
rense -at- mac.com

I have to thank you + Marc for these pages. They really got me started. I never imagined I would be setting up and running the latest Apache, PHP and MySQL on my Mac. Thanks!


  01/25/02

where's the line

$dbh = mysql_connect("localhost","root","your_password");

I type it as it as in the terminal but it says Badly placed ()'s. HELP


PHP and MySQL don't talk: undefined function 01/29/02
sharrison -at- licor.com

After getting Apache, PHP, and MySQL all properly installed, I have since been stymied by an error getting PHP to connect to MySQL. When calling a mysql_connect() the browser displays the following error:
Fatal error: Call to undefined function: () in /public_html/index.php on line 8

Ugh. Haven't found an answer anywhere. Some allusions to php.ini, but nothing concrete. Anyone have any ideas?


good script... 01/29/02
francoisbrochu(NOSPAM) -at- yahoo.com

It did not work the first time ....
I check the curly brace added a few
echo "&lt;P&gt;$dbh this line is ". __LINE__."&lt;/P&gt;";
This way I know which line I am on and I have a MySQL resource.
I see what need to be change
WORK FINE NOW
....
As for the security (once your started)
You should not be using root acess for a web application NEVER
create a new web-user with limited privilige (from localhost) such as select_priv, insert_priv, update_priv.
NO MORE
use a field to indicate if record is active or inactive to the web.
this way if you ever get hack (or in blonde moment) you may get info overload but you wont loose data
save you delete and drop for the comand line and don't forget to back up


Error 1146 ?? 02/06/02
randy -at- walkersystems.net

As for the textedit/rtf delemma above, Under the FORMAT menu is a command "Make plain text" use that and then save as with the name index.php but don't forget to check the "Hide extension" at the bottom or it will end up saving as index.php.txt.

Now, having saved it correctly, I loaded it and got the following error.


1146: Table 'CONTACT.CONTACT_INFO' doesn't exist

If I go into terminal and the mysql program I get the following, proving it DOES exist:



mysql> show tables;
+-------------------+
| Tables_in_CONTACT |
+-------------------+
| CONTACT_INFO |
+-------------------+
1 row in set (0.00 sec)

mysql> drop database CONTACT;
Query OK, 3 rows affected (0.42 sec)

mysql>




Why can't the browser find it? I installed PHP in /Library/Webserver/ instead of in my home dir. Could that be the reason? Please email me a reply. Thanx..

-Randy


Error 1146 FIXED! 02/06/02
randy -at- walkersystems.net

I had installed PHP by following the O'Reilly tutorial. Went back and installed the ver 4.1.1 from entropy.ch and reinstalled the MySQL from same page and all worked fine.

WHEW! Now, I just want to be able to use the examples in the php/MySQL book I just bought, "PHP and MySQL Web Development" from SAMS. Hope it all works....

Thanx for the help!
-Randy


  02/18/02
akaCraig -at- bungo.com

Erik -
You rock! That was a super straight forward tutorial. Could not have been easier.
May good things come your way.
Thank You


Thanks 03/03/02
dmhames -at- psprinting.com

Thanks for providing this helpful info.


Xcellent 03/05/02
pinguito -at- ifrance.com

Just great : It works and I'm happy !!!


Moving data from SQLServer 03/18/02
webmaster -at- 8realms.com

I've got PHP/MySQL working beautifully, but am now moving on to the next hurdle: moving data from SQL/Server into my MySQL installation... any ideas?


Delete a row / the whole database... 04/24/02
my name...

Hello everyone...

Please reply here if you know how to delete a row or the whole database (with the source code on thsi page)

Thx for replying


thanks for the tutorial 04/25/02
Joel Philip

Erik, thanks for writing this tutorial. It got me up to speed on using mysql on mac os x.
Ive been using mysql on a linux server and now I can run it locally on my machine.
woohoo!


Thank you! 05/06/02
Maria Trujillo

Excellent intro to the complexities of PHP/MySQL.
My colleague was trying to go back to ASP/MSAccess but thanks to this site I think she is convinced!


MySQL HELP 06/09/02
Alex
alex -at- thundernet.com

I've attempted to install MySQL but I can't seem to connect to the server. When attempting to connect I recieve: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"

The MacOS X machine is a LAN client and does not have it's own domain other than localhost.

Any thoughts would be GREATLY appreciated.

Thanks,
Alex


$_POST 06/27/02
Phil
admin-alias -at- cogeco.ca

Is there any updated tutorials out there explaining how to pass variables from a form to your database using $_POST ..?


msql login error 07/09/02
andrew

the solution to this error:

[localhost:~] hoffj% sudo mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

which occurs on the command line, is NOT to do this:

$dbh = mysql_connect("localhost","root","your_password");

which you would do from a script, but rather, to do this (from the commandline):

mysql -u root -pmypassword

where root is the root mysql database user, not the system's superuser, and mypassword is the password you set for that root mysql database user.

note that there is NO space between the -p password option and the password itself.

you enter that command as an ordinary user. no su or sudo required.


Macromedia MX 07/20/02
mrenaissance
jfd -at- paintingwlight.com

This is very cool. But I am having trouble getting dreamweaver mx to see my database. Does anyone know the proper way to configure this?

gracias


MYSQL Connection Problem 07/23/02
Tommy
mysql3 -at- hotmail.com

I have followed these instructions below, but cannot connect to MYSQL.

Installed 3.23.51.pkg.tar.gz
Create user
Name: "MySQL User"
Short Name: "mysql"
Password:*******
type "cd /usr/local/mysql"
type "sudo ./scripts/mysql_install_db", enter administrator
type "sudo chown -R mysql /usr/local/mysql/*"
type "sudo ./bin/safe_mysqld --user=mysql &"
Use it with "mysql test"
and get the error "ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"
Tired this command
"cd /usr/local/mysql; sudo ./bin/safe_mysqld --user=mysql &"
-same error
I must be missing something wrong, help?


MYSQL Connection Problem 07/23/02
Tommy
mysql3 -at- hotmail.com

I have followed these instructions below, but cannot connect to MYSQL.

Installed 3.23.51.pkg.tar.gz
Create user
Name: "MySQL User"
Short Name: "mysql"
Password:*******
type "cd /usr/local/mysql"
type "sudo ./scripts/mysql_install_db", enter administrator
type "sudo chown -R mysql /usr/local/mysql/*"
type "sudo ./bin/safe_mysqld --user=mysql &"
Use it with "mysql test"
and get the error "ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"
Tired this command
"cd /usr/local/mysql; sudo ./bin/safe_mysqld --user=mysql &"
-same error
I must be missing something wrong, help?


Works on 10.2! 07/28/02
avarame

I used Marc Liyanage's instructions to install mysql onto Jaguar 10.2 build 6c106. While the command line 'mysql' tool didn't work (errors with libraries), the daemon seemed to run. I poked around a bit for a simple php-based test, and voila! Thanks much Erik! And to all you Jaguar users - never fear, php is fine, but no cli for now =(


need help 08/06/02
will

I created a discussion forum with php4 and mysql. That text is mixed up if I don't type tags like . How should I fix the problem? I appreciate for your help.


GuestBook 09/14/02
Ricardo Chavarria

Hi, I downloaded a guestbook from http://php.inc.ru and configured everything, you can see it here http://200.46.150.15/~sku/evidelio/guestbook/gb.php

the thing is, when i try to add an entry to the guestbook, nothing happens, the page processes something and nothing happens. I cheked the MySQL database to see if something was written on it, but nothing was passed on to the database.

I mannually added an entry from withing Mac OS X's Terminal into the database, and that is the only one that shows up.

What gives? any suggestions??


This script works excellent! 09/30/02
Peter

Thank you for this helpful information!
As a web-and starting database developer, I want to learn as fast as possibe: time is money and this example got me up to speed.

Thanks!

Peter


Error 1044create database CONTACT' at line 1 10/22/02
M.Nieuwpoort
info -at- e-BS.nl

create database CONTACT' at line 1
mysql> create database CONTACT;
ERROR 1044: Access denied for user: '@localhost' to database 'CONTACT'
mysql>

what's wrong please hepl me.. wanne use mysql on a mac !!


how to config php4 on osx? 10/27/02
boomboom
nickturner -at- mac.com
http://theboomboomroom.dyndns.org/connect2me/

In entropy's php 4.2.3 for Jaguar, there isn't a php.ini file that you would use to configure options. Does anyone know how to get around this?


socket connection error 12/08/02
albedo
albedo -at- flashmail.com

Hi,

as fo many of us i can't connect to mysql trhough socket when configured ad a LAN client.

What I would greatly appreciate is an explanation of what is going on.

Tks




Can't connect to local MySQL server... 12/17/02
beeners

I got it to work by changing the $dbh statement as follows:

$dbh = mysql_connect("127.0.0.1","root","password");

Now all is well. Hope this helps those who are having connection problems.


Cannot connect and other stuff 01/09/03
Frank Janssens
fjanssens -at- mac.com

Probably it's due to my lack of knowledge in Unix.
PHP works fine but mysql is a pain in the a.

Most of the time I get te warning:ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Or mysql is alraedy started. Or cannot find mysql server.

This is what I got now in the terminal:

[ovpserv3:/usr/local/mysql] mysql% sudo mysql
Password:
dyld: ./bin/mysql Undefined symbols:
./bin/mysql undefined reference to _BC expected to be defined in /usr/lib/libSystem.B.dylib
./bin/mysql undefined reference to _PC expected to be defined in /usr/lib/libSystem.B.dylib
./bin/mysql undefined reference to _UP expected to be defined in /usr/lib/libSystem.B.dylib
Trace/BPT trap

I am actually a Filemaker user and this seems to me a giant step back into the stone age. Unfortunately I am forced to use mysql.

Anyone has a hint ?


ARGHHHGHGH 01/14/03
Martin Lee
martin -at- cometblue.com

Well, I get this for a start:
1146: Table 'CONTACT.CONTACT_INFO' doesn't exist

Also, when I type in the terminal, mysql, as my normal user, it all runs fine, as root it does not let me in.
I can use yourSQL, when I type mlee into the user field, and leave the login field blank. Surely this cannot be secure.
Help, please!!!


mysql/php error 01/22/03
nick
nick -at- osprey.net

i hit index.php from IE
and see the following which I open index.php

", $first_name, $last_name, $phone); } ?>

any ideas?

tia
great tutorial


lib errors 02/17/03
cor
corz -at- how.to
http://corz.webfyx.com

to the guys getting the lib errors: you need to get the latest version of MYSQL. The one you are running is for Jaguar 10.1.

If you use the up to date entropy packages you literally can't go wrong.
;o)

ps.. check out cocoaMYSQL for database management.


MS Access to MySQL 02/23/03
lol
satch_man -at- mac.com

Thanks for a great tutorial!

I need to set up a link between an MSAccess datatbase (on PC of course) and the MySQL database now running sweetly on my Mac.

I have to transfer data from Access to MySQL not the other way (at least for now).

How do I do this? I have heard of ODBC but have no experience using it. Any help very gratefully received.


PHP & mySQL tutorial 07/01/03
Keith Villmer

Super tutorial! Worked beautifully once I got past the need for the root password. For the time being I am coding it into the 3rd param of the connect statement. Something more secure to follow.
Thanks!


php/mysql intergration 10/08/04
jhiggins
http://www.signifier.co.uk/

I have spent two works trying to get php and mysql communicating with each other, working thru every stage, learning how to use terminal, finding out about .conf files etc.etc. and still I couldn't get them talking.5 minutes on this page and a copy here and a paste there and bingo it's done! Thank you very much!


Can't connect either. 01/04/05

Sorry, but nothing in this forum proved useful. :(

I got error 1045 as well, and there isn't a single damned post here that helps deal with it.

Would somepne please lucidly describe precisely what this error means, and what precisely can be done to alleviate it, short of deciding that MySQL is a lousy product and abandoning it entirely?


mysql & php on Mac OS X 01/04/05
bart

I cannot get php and mySql to communicate with each other. Do I need to do something in the apache web server?

Please advise, thanks in advance.


could not connect mysql.sock 01/26/05
sarah

Hi! I found a solution to this at Marc liyanages homepage:


(with a little change as I used serverlogistics mysql)


http://www.entropy.ch/software/macosx/mysql/
"Database Re-Initialization
Sometimes the scripts in the installer package do not work correctly, preventing the startup of the database server. Sometimes you need to reinitialize for other reasons, when the database is too screwed up. So if you have problems and you want a fresh start, perform these steps manually and then try again to start the server:
1. sudo find /usr/local/2. mysql/data -type f -exec rm {} ';'
3. sudo hostname 127.0.0.1
4. cd /usr/local/mysql
5.

here I made a change: my "mysql_install_db was inside "bin" and not "scrpits": si I exchange it! Which makes it this


5. sudo ./bin/mysql_install_db
6. sudo chown -R mysql data/

And then: no more socket not found! yeah!


perfect! 08/23/05
Paco Ruiz

I already installed all following the instructions and all is perfect!! running on OSX 10.4.2, ibook G4.


dreamweaver (studio 8) 10/30/05
Polly McAleer
mcmail7 -at- verizon.net

How do I get a page that has a gallery, which works great on localserver, on to my site. Do I copy and paste the whole script or just use links. When I go to browser it says page not found. Or,.. what the hell. Does anyone know or could tell me exactly...how to set up my dynamic site that's probably the problem. Maybe??? Somebody help me!!!!!!!!!!!!Please, deadline, and I don't know what I am doing.....so much for trying to get creative. eh?


Socket Error Fix 05/23/06
Stuball
chameleonxl -at- yahoo.com

solved the problem by modifying to this:

$dbh = mysql_connect("127.0.0.1","root","");


Socket Error Fix 05/23/06
Stuball
chameleonxl -at- yahoo.com

solved the problem by modifying to this:

$dbh = mysql_connect("127.0.0.1","root","");


Socket Error Fix 05/23/06
Stuball
chameleonxl -at- yahoo.com

and changing the "mysql_create_db($database_name)" to "mysql_query("CREATE DATABASE $database_name"


Leave a Comment

Show Comment Form

© 1996-2008 Timestretch.com
About